Skip to content

Commit

Permalink
Merge pull request #167 from sgarciac/master
Browse files Browse the repository at this point in the history
Parse all options before calling the step files generation
  • Loading branch information
josepjaume committed Sep 17, 2014
2 parents 4d771d9 + 309ddce commit 7b6bfe4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lib/spinach/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ def initialize(args = ARGV)
def run
options

return true if Spinach.config.generate

Spinach::Runner.new(feature_files).run
if Spinach.config.generate
Spinach::Generators.run(feature_files)
else
Spinach::Runner.new(feature_files).run
end
end

# @return [Hash]
Expand Down Expand Up @@ -109,7 +111,6 @@ def parse_options
opts.on('-g', '--generate',
'Auto-generate the feature steps files') do
config[:generate] = true
Spinach::Generators.run(feature_files)
end

opts.on_tail('--version', 'Show version') do
Expand Down
3 changes: 3 additions & 0 deletions lib/spinach/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ module Generators
# @files [Array]
# filenames to evaluate for step generation
def self.run(files)
successful = true
files.each do |file|
feature = Parser.open_file(file).parse

begin
FeatureGenerator.new(feature).store
rescue FeatureGeneratorException => e
successful = false
$stderr.puts e
end
end
successful
end
end
end
Expand Down
17 changes: 14 additions & 3 deletions test/spinach/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,28 @@
end

describe 'generate' do
%w{-g --generate}.each do |opt|
it 'inits the generator if #{opt}' do
%w{-g --generate}.each do |generate_opt|
it 'inits the generator if #{generate_opt}' do
config = Spinach::Config.new
Spinach.stubs(:config).returns(config)

Spinach::Generators.expects(:run)

Spinach::Cli.new([opt]).run
Spinach::Cli.new([generate_opt]).run

config.generate.must_equal true
end

%w{-f --features_path}.each do |feature_path_opt|
it "honors the #{feature_path_opt} option" do
config = Spinach::Config.new
Spinach.stubs(:config).returns(config)
cli = Spinach::Cli.new([feature_path_opt,"custom_path", generate_opt])
cli.options
config.features_path.must_equal 'custom_path'
end
end

end
end

Expand Down

0 comments on commit 7b6bfe4

Please sign in to comment.