Skip to content

Commit

Permalink
Merge pull request #161 from sweet-t/feature_filename
Browse files Browse the repository at this point in the history
Feature filename
  • Loading branch information
josepjaume committed Jul 3, 2014
2 parents 49372b2 + 767a11c commit 4534226
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/spinach/feature.rb
@@ -1,6 +1,6 @@
module Spinach
class Feature
attr_accessor :line
attr_accessor :filename, :line
attr_accessor :name, :scenarios, :tags
attr_accessor :background
attr_accessor :description
Expand All @@ -14,5 +14,8 @@ def background_steps
@background.nil? ? [] : @background.steps
end

def line=(value)
@line = value.to_i if value
end
end
end
2 changes: 2 additions & 0 deletions lib/spinach/runner.rb
Expand Up @@ -73,6 +73,8 @@ def run
filename.split(':')
end.each do |filename, line|
feature = Parser.open_file(filename).parse
feature.filename = filename
feature.line = line
success = FeatureRunner.new(feature, line).run
successful = false unless success
break if fail_fast? && !successful
Expand Down
26 changes: 24 additions & 2 deletions test/spinach/runner_test.rb
Expand Up @@ -76,7 +76,7 @@
@feature_runner = stub
filenames.each do |filename|
Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub
parser.stubs(:parse).returns feature = stub
parser.stubs(:parse).returns feature = Spinach::Feature.new
Spinach::Runner::FeatureRunner.stubs(:new).
with(feature, anything).
returns(@feature_runner)
Expand All @@ -101,13 +101,35 @@
runner.run.must_equal false
end

describe 'when line set' do
let(:filename) { 'features/cool_feature.feature' }
let(:line) { 12 }
let(:filenames) { ["#{filename}:#{line}"] }
let(:runner) { Spinach::Runner.new(filenames) }

it 'sets filename and line on the feature' do
@feature_runner = stub
Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub
parser.stubs(:parse).returns feature = Spinach::Feature.new
Spinach::Runner::FeatureRunner.stubs(:new).
with(feature, anything).
returns(@feature_runner)
runner.stubs(required_files: [])
@feature_runner.stubs(:run).returns(true)

runner.run.must_equal true
feature.filename.must_equal filename
feature.line.must_equal line
end
end

describe "when fail_fast set" do
let(:feature_runners) { [ stub, stub ] }

before(:each) do
filenames.each_with_index do |filename, i|
Spinach::Parser.stubs(:open_file).with(filename).returns parser = stub
parser.stubs(:parse).returns feature = stub
parser.stubs(:parse).returns feature = Spinach::Feature.new
Spinach::Runner::FeatureRunner.stubs(:new).
with(feature, anything).
returns(feature_runners[i])
Expand Down

0 comments on commit 4534226

Please sign in to comment.