Class: Viewcumber

Inherits:
Cucumber::Formatter::Json
  • Object
show all
Defined in:
lib/viewcumber.rb

Defined Under Namespace

Modules: GherkinObjectAttrs

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(step_mother, path_or_io, options) ⇒ Viewcumber

Returns a new instance of Viewcumber.



50
51
52
53
54
55
56
# File 'lib/viewcumber.rb', line 50

def initialize(step_mother, path_or_io, options)
  make_output_dir
  copy_app
  copy_public_folder
  super(step_mother, File.open(results_filename, 'w+'), options)
  @gf.extend GherkinObjectAttrs
end

Class Attribute Details

.last_step_htmlObject

Returns the value of attribute last_step_html.



37
38
39
# File 'lib/viewcumber.rb', line 37

def last_step_html
  @last_step_html
end

Class Method Details

.rewrite_css_and_image_references(response_html) ⇒ Object

:nodoc:



39
40
41
42
43
44
45
46
47
# File 'lib/viewcumber.rb', line 39

def rewrite_css_and_image_references(response_html) # :nodoc:
  return response_html unless Capybara.asset_root
  directories = Dir.new(Capybara.asset_root).entries.inject([]) do |list, name|
    list << name if File.directory?(File.join(Capybara.asset_root, name)) and not name.to_s =~ /^\./
    list
  end
  response_html.gsub!(/("|')\/(#{directories.join('|')})/, '\1public/\2')
  response_html.gsub(/("|')http:\/\/.*\/images/, '\1public/images') 
end

Instance Method Details

#after_feature(feature) ⇒ Object

The JSON formatter adds the background as a feature element, we only want full scenarios so lets delete all with type ‘background’



70
71
72
73
74
75
76
77
78
# File 'lib/viewcumber.rb', line 70

def after_feature(feature)
  # this might want to be feature_hashes and an each
  if @gf.feature_hash && @gf.feature_hash['elements']
    @gf.feature_hash['elements'].delete_if do |element|
      element['type'] == 'background'
    end
  end
  super(feature)
end

#after_step(step) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/viewcumber.rb', line 58

def after_step(step)

  additional_step_info = { 'html_file' => write_html_to_file(Viewcumber.last_step_html), 
                           'emails' => emails_for_step(step) }

  current_element = @gf.feature_hash['elements'].last
  current_step = current_element['steps'].last
  current_step.merge!(additional_step_info)
end