Class: Magicspec::MagicspecFormatter

Inherits:
RSpec::Core::Formatters::HtmlFormatter
  • Object
show all
Defined in:
lib/magicspec/generators/magicspec/config/magicspec_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ MagicspecFormatter

Returns a new instance of MagicspecFormatter.



7
8
9
10
11
12
13
# File 'lib/magicspec/generators/magicspec/config/magicspec_formatter.rb', line 7

def initialize(output)
  output = File.new(File.expand_path(File.join('.', 'app', 'reports', "#{Time.now.strftime("%Y%m%d_%H%M%S")}.html")), 'w')
  super(output)
  @printer.class.send(:define_method, 'puts') do |what|
    @output.puts what
  end #define_method
end

Instance Method Details

#example_failed(example) ⇒ Object

Check if this is browser and we’ll add some content.



16
17
18
19
20
21
22
23
24
# File 'lib/magicspec/generators/magicspec/config/magicspec_formatter.rb', line 16

def example_failed(example)
  super(example)
  if $navi
    failed_url = $navi.url rescue $navi.current_url
    @printer.puts "<a target=\"_blank\" href=\"#{failed_url}\">failed url is [#{failed_url}]</a>"
    @printer.puts '<br />'
    @printer.flush
  end #if
end

#example_passed(example) ⇒ Object



26
27
28
29
# File 'lib/magicspec/generators/magicspec/config/magicspec_formatter.rb', line 26

def example_passed(example)
  super(example)
  @printer.flush
end

#extra_failure_content(failure) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/magicspec/generators/magicspec/config/magicspec_formatter.rb', line 31

def extra_failure_content(failure)
  browser = example_group.before_all_ivars[:@browser] || @browser
  # If we'ere dealing with a browser get a screenshot on failure
  if browser
    browser.screenshot.save File.expand_path(File.join('.', 'app', 'reports','screenshots', "#{Time.now.strftime("%Y%m%d_%H%M%S")}.png"))      
    
    # Need to figure out how to remotely upload
    content = []
    content << "<span>"
    content << "<a target='_blank' href='http://127.0.0.1:8020/o365/app/reports/screenshots/20131031_103612.png'>screenshot</a>"
    content << "</span>"
    super + content.join($/)
  end
end