Skip to content

Commit

Permalink
Merge 19d8e7d into 90a0098
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonah Hirsch committed Mar 30, 2016
2 parents 90a0098 + 19d8e7d commit 8f11ab4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/spinach/feature.rb
@@ -1,6 +1,6 @@
module Spinach
class Feature
attr_accessor :filename, :line
attr_accessor :filename, :lines
attr_accessor :name, :scenarios, :tags
attr_accessor :background
attr_accessor :description
Expand All @@ -14,8 +14,8 @@ def background_steps
@background.nil? ? [] : @background.steps
end

def line=(value)
@line = value.to_i if value
def lines=(value)
@lines = value.map(&:to_i) if value
end
end
end
28 changes: 19 additions & 9 deletions lib/spinach/runner.rb
Expand Up @@ -69,15 +69,25 @@ def run

successful = true

filenames.map do |filename|
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
filenames.map! do |filename|
file, *lines = filename.split(":")
[file, lines]
end

catch :fail do
filenames.each do |filename, lines|
lines = [nil] if lines.empty?

feature = Parser.open_file(filename).parse
feature.filename = filename
feature.lines = lines

lines.each do |line|
success = FeatureRunner.new(feature, line).run
successful = false unless success
throw :fail if fail_fast? && !successful
end
end
end

Spinach.hooks.run_after_run(successful)
Expand Down
9 changes: 9 additions & 0 deletions test/spinach/cli_test.rb
Expand Up @@ -257,6 +257,15 @@
end
end

describe "when a particular feature list is passed with multiple lines" do
it "returns the feature with the line numbers" do
cli = Spinach::Cli.new(['features/some_feature.feature:10:20'])
File.stubs(:exists?).returns(true)

cli.feature_files.must_equal ["features/some_feature.feature:10:20"]
end
end

describe 'when no feature is passed' do
it 'returns all the features' do
cli = Spinach::Cli.new([])
Expand Down
45 changes: 44 additions & 1 deletion test/spinach/runner_test.rb
Expand Up @@ -119,7 +119,50 @@

runner.run.must_equal true
feature.filename.must_equal filename
feature.line.must_equal line
feature.lines.must_equal [line]
end
end

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

before(:each) 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: [])
end

it "sets filename and lines on the feature" do
@feature_runner.stubs(:run).returns(true)
runner.run.must_equal true
@feature.filename.must_equal filename
@feature.lines.must_equal line.split(":").map(&:to_i)
end

it "returns false if it fails" do
@feature_runner.stubs(:run).returns(false)
runner.run.must_equal false
end

it "breaks with a failure when fail fast set" do
Spinach.config.stubs(:fail_fast).returns true
@feature_runner.stubs(:run).returns(false)
@feature_runner.expects(:run).never
runner.run.must_equal false
end

it "does not break when success when fail fast set" do
Spinach.config.stubs(:fail_fast).returns true
@feature_runner.stubs(:run).returns(true)
@feature_runner.expects(:run).returns true
runner.run.must_equal true
end
end

Expand Down

0 comments on commit 8f11ab4

Please sign in to comment.