Class: Res::Formatters::RubyCucumber
- Inherits:
-
Object
- Object
- Res::Formatters::RubyCucumber
- Includes:
- Cucumber::Formatter::Io, FileUtils
- Defined in:
- lib/res/formatters/ruby_cucumber.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_background(background) ⇒ Object
- #after_feature(feature) ⇒ Object
-
#after_feature_element(feature_element) ⇒ Object
After a scenario.
-
#after_features(features) ⇒ Object
Once everything has run – whack it in a ResultIR object and dump it as json.
- #after_multiline_arg(multiline_arg) ⇒ Object
- #after_outline_table(outline_table) ⇒ Object
- #after_table_cell(cell) ⇒ Object
- #after_table_row(table_row) ⇒ Object
- #after_tags(tags) ⇒ Object
- #background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
- #before_background(background) ⇒ Object
- #before_feature(feature) ⇒ Object
- #before_feature_element(feature_element) ⇒ Object
- #before_features(features) ⇒ Object
- #before_multiline_arg(multiline_arg) ⇒ Object
-
#before_outline_table(outline_table) ⇒ Object
Before a scenario outline is encountered.
- #before_step(step) ⇒ Object
- #before_table_row(table_row) ⇒ Object
- #comment_line(comment_line) ⇒ Object
- #examples_name(keyword, name) ⇒ Object
- #exception(exception, status) ⇒ Object
-
#feature_name(keyword, name) ⇒ Object
{ :type => ‘Feature’, :name => ‘Feature name’, :description => “As a blahnAs a blahn” }.
-
#initialize(runtime, path_or_io, options) ⇒ RubyCucumber
constructor
A new instance of RubyCucumber.
- #scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
-
#step_name(keyword, step_match, status, source_indent, background, *args) ⇒ Object
Argument list changed after cucumber 1.4, hence the *args.
- #table_cell_value(value, status) ⇒ Object
- #tag_name(tag_name) ⇒ Object
Constructor Details
#initialize(runtime, path_or_io, options) ⇒ RubyCucumber
Returns a new instance of RubyCucumber.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 14 def initialize(runtime, path_or_io, ) cucumber_version = %x(cucumber --version) @cucumber_version = cucumber_version.gsub("\n","") @runtime = runtime @io = ensure_io(path_or_io, "reporter") @options = @exceptions = [] @indent = 0 @prefixes = [:prefixes] || {} @delayed_messages = [] @_start_time = Time.now end |
Class Method Details
.split_uri(uri) ⇒ Object
234 235 236 237 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 234 def self.split_uri(uri) strings = uri.rpartition(/:/) { :file => strings[0], :line => strings[2].to_i, :urn => uri } end |
Instance Method Details
#after_background(background) ⇒ Object
136 137 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 136 def after_background(background) end |
#after_feature(feature) ⇒ Object
92 93 94 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 92 def after_feature(feature) @_feature[:finished] = Time.now() end |
#after_feature_element(feature_element) ⇒ Object
After a scenario
123 124 125 126 127 128 129 130 131 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 123 def after_feature_element(feature_element) @_context = {} if feature_element.respond_to? :status @_feature_element[:status] = feature_element.status end @_feature_element[:finished] = Time.now @_feature_element[:values] = Res.perf_data.pop if !Res.perf_data.empty? end |
#after_features(features) ⇒ Object
Once everything has run – whack it in a ResultIR object and dump it as json
34 35 36 37 38 39 40 41 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 34 def after_features(features) results = @_features ir = ::Res::IR.new( :started => @_start_time, :finished => Time.now(), :results => results, :type => 'Cucumber' ) @io.puts ir.json end |
#after_multiline_arg(multiline_arg) ⇒ Object
184 185 186 187 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 184 def after_multiline_arg(multiline_arg) @_context[:args] = multiline_arg.to_s.gsub(/\e\[(\d+)m/, '') @_table = nil end |
#after_outline_table(outline_table) ⇒ Object
198 199 200 201 202 203 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 198 def after_outline_table(outline_table) headings = @_table.shift description = @_outlines.collect{ |o| o[:name] }.join("\n") + "\n" + headings[:name] @_feature_element[:children] = @_table @_feature_element[:description] = description end |
#after_table_cell(cell) ⇒ Object
225 226 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 225 def after_table_cell(cell) end |
#after_table_row(table_row) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 210 def after_table_row(table_row) if table_row.class == Cucumber::Ast::OutlineTable::ExampleRow @_current_table_row[:name] = table_row.name if table_row.exception @_current_table_row[:message] = table_row.exception.to_s end if table_row.scenario_outline @_current_table_row[:status] = table_row.status end @_current_table_row[:line] = table_row.line @_current_table_row[:urn] = @_feature_element[:file] + ":" + table_row.line.to_s @_table << @_current_table_row end end |
#after_tags(tags) ⇒ Object
70 71 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 70 def () end |
#background_name(keyword, name, file_colon_line, source_indent) ⇒ Object
139 140 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 139 def background_name(keyword, name, file_colon_line, source_indent) end |
#before_background(background) ⇒ Object
133 134 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 133 def before_background(background) end |
#before_feature(feature) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 43 def before_feature(feature) @_feature = {} @_context = {} @_feature[:started] = Time.now() begin if @cucumber_version.to_f < 1.3.to_f uri = feature.file.to_s else uri = feature.location.to_s end hash = RubyCucumber.split_uri( uri ) @_feature[:file] = hash[:file] @_feature[:line] = hash[:line] @_feature[:urn] = hash[:urn] rescue @_feature[:uri] = 'unknown' end @_features << @_feature @_context = @_feature end |
#before_feature_element(feature_element) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 96 def before_feature_element(feature_element) @_feature_element = {} @_context = {} @_feature_element[:started] = Time.now begin if @cucumber_version.to_f < 1.3.to_f uri = feature_element.file_colon_line else uri = feature_element.location.to_s end hash = RubyCucumber.split_uri( uri ) @_feature_element[:file] = hash[:file] @_feature_element[:line] = hash[:line] @_feature_element[:urn] = hash[:urn] rescue => e @_feature_element[:error] = e. @_feature_element[:file] = 'unknown' end @_feature[:children] = [] if ! @_feature[:children] @_feature[:children] << @_feature_element @_context = @_feature_element end |
#before_features(features) ⇒ Object
28 29 30 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 28 def before_features(features) @_features = [] end |
#before_multiline_arg(multiline_arg) ⇒ Object
181 182 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 181 def before_multiline_arg(multiline_arg) end |
#before_outline_table(outline_table) ⇒ Object
Before a scenario outline is encountered
190 191 192 193 194 195 196 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 190 def before_outline_table(outline_table) # Scenario outlines appear as children like normal scenarios, # but really we just want to construct normal-looking children # from them @_outlines = @_feature_element[:children] @_table = [] end |
#before_step(step) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 150 def before_step(step) @_step = {} # Background steps can appear totally divorced from scenerios (feature # elements). Need to make sure we're not including them as children # to scenario that don't exist return if @_feature_element && @_feature_element[:finished] @_feature_element = {} if !@_feature_element @_feature_element[:children] = [] if !@_feature_element[:children] @_feature_element[:children] << @_step @_context = @_step end |
#before_table_row(table_row) ⇒ Object
205 206 207 208 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 205 def before_table_row(table_row) @_current_table_row = { :type => 'Cucumber::ScenarioOutline::Example' } @_table = [] if !@_table end |
#comment_line(comment_line) ⇒ Object
65 66 67 68 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 65 def comment_line(comment_line) @_context[:comments] = [] if !@_context[:comments] @_context[:comments] << comment_line end |
#examples_name(keyword, name) ⇒ Object
142 143 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 142 def examples_name(keyword, name) end |
#exception(exception, status) ⇒ Object
177 178 179 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 177 def exception(exception, status) @_context[:message] = exception.to_s end |
#feature_name(keyword, name) ⇒ Object
{ :type => ‘Feature’,
:name => 'Feature name',
:description => "As a blah\nAs a blah\n" }
82 83 84 85 86 87 88 89 90 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 82 def feature_name(keyword, name) @_feature[:type] = "Cucumber::" + keyword.gsub(/\s+/, "") lines = name.split("\n") lines = lines.collect { |l| l.strip } @_feature[:name] = lines.shift @_feature[:description] = lines.join("\n") end |
#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object
145 146 147 148 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 145 def scenario_name(keyword, name, file_colon_line, source_indent) @_context[:type] = "Cucumber::" + keyword.gsub(/\s+/, "") @_context[:name] = name || '' end |
#step_name(keyword, step_match, status, source_indent, background, *args) ⇒ Object
Argument list changed after cucumber 1.4, hence the *args
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 165 def step_name(keyword, step_match, status, source_indent, background, *args) file_colon_line = args[0] if args[0] @_step[:type] = "Cucumber::Step" name = keyword + step_match.format_args(lambda{|param| %{#{param}}}) @_step[:name] = name @_step[:status] = status @_step[:type] = "Cucumber::Step" end |
#table_cell_value(value, status) ⇒ Object
228 229 230 231 232 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 228 def table_cell_value(value, status) @_current_table_row[:children] = [] if !@_current_table_row[:children] @_current_table_row[:children] << { :type => "Cucumber::ScenarioOutline::Parameter", :name => value, :status => status } end |
#tag_name(tag_name) ⇒ Object
73 74 75 76 77 |
# File 'lib/res/formatters/ruby_cucumber.rb', line 73 def tag_name(tag_name) @_context[:tags] = [] if !@_context[:tag] # Strip @ from tags @_context[:tags] << tag_name[1..-1] end |