features/steps/cli.rb in newgem-1.0.1 vs features/steps/cli.rb in newgem-1.0.2

- old
+ new

@@ -1,40 +1,42 @@ Given %r{^a safe folder} do FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp" FileUtils.mkdir_p @tmp_root + @newgem_lib_path = File.expand_path(File.dirname(__FILE__) + '/../../lib') end Given /^this project is active project folder/ do - FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp" - FileUtils.mkdir_p @tmp_root + Given "a safe folder" @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..") end Given /^env variable \$([\w_]+) set to '(.*)'/ do |env_var, value| ENV[env_var] = value end -def force_local_newgem_priority(project_name) +def force_local_newgem_priority(project_name = @project_name) rakefile = File.read(File.join(project_name, 'Rakefile')) File.open(File.join(project_name, 'Rakefile'), "w+") do |f| - f << "$:.unshift('#{File.expand_path(File.dirname(__FILE__) + '/../../lib')}')\n" + f << "$:.unshift('#{@newgem_lib_path}')\n" f << rakefile end end -Given %r{^an existing newgem scaffold \[called '(.*)'\]$} do |project_name| - # TODO this is a combo of "a safe folder" and "newgem is executed ..." steps; refactor - FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp" - FileUtils.mkdir_p @tmp_root +def setup_active_project_folder project_name + @active_project_folder = File.join(@tmp_root, project_name) + @project_name = project_name +end + +Given %r{^an existing newgem scaffold \[called '(.*)'\]} do |project_name| + Given "a safe folder" newgem = File.expand_path(File.dirname(__FILE__) + "/../../bin/newgem") + setup_active_project_folder project_name FileUtils.chdir @tmp_root do @stdout = "newgem.out" system "ruby #{newgem} #{project_name} > #{@stdout}" - force_local_newgem_priority project_name + force_local_newgem_priority end - @active_project_folder = File.join(@tmp_root, project_name) - @project_name = project_name end Given /^project website configuration for safe folder on local machine$/ do @remote_folder = File.expand_path(File.join(@tmp_root, 'website')) FileUtils.rm_rf @remote_folder @@ -53,26 +55,25 @@ end end When %r{^newgem is executed for project '(.*)' with no options$} do |project_name| newgem = File.expand_path(File.dirname(__FILE__) + "/../../bin/newgem") + setup_active_project_folder project_name FileUtils.chdir @tmp_root do @stdout = "newgem.out" system "ruby #{newgem} #{project_name} > #{@stdout}" - force_local_newgem_priority project_name + force_local_newgem_priority end - @active_project_folder = File.expand_path(File.join(@tmp_root, project_name)) - @project_name = project_name end When %r{^newgem is executed for project '(.*)' with options '(.*)'$} do |project_name, arguments| newgem = File.expand_path(File.dirname(__FILE__) + "/../../bin/newgem") - @project_name = project_name + setup_active_project_folder project_name FileUtils.chdir @tmp_root do @stdout = "newgem.out" system "ruby #{newgem} #{arguments} #{project_name} > #{@stdout}" - @active_project_folder = File.join(@tmp_root, project_name) + force_local_newgem_priority end end When %r{^'(.*)' generator is invoked with arguments '(.*)'$} do |generator, arguments| FileUtils.chdir(@active_project_folder) do @@ -98,13 +99,13 @@ system "ruby #{test_file} > #{@stdout}" end end When /^task 'rake (.*)' is invoked$/ do |task| - @raketask_stdout = File.expand_path(File.join(@tmp_root, "tests.out")) + @stdout = File.expand_path(File.join(@tmp_root, "tests.out")) FileUtils.chdir(@active_project_folder) do - system "rake #{task} > #{@raketask_stdout} 2> #{@raketask_stdout}" + system "rake #{task} --trace > #{@stdout} 2> #{@stdout}" end end Then %r{^folder '(.*)' is created} do |folder| FileUtils.chdir @active_project_folder do @@ -153,13 +154,15 @@ actual_output = File.read(@stdout) actual_output.should match(/#{opt1}/) actual_output.should match(/#{opt2}/) end -Then /^output matches \/(.*)\/$/ do |regex| +Then /^output (does|does not) match \/(.*)\/$/ do |does, regex| actual_output = File.read(@stdout) - actual_output.should match(/#{regex}/) + (does == 'does') ? + actual_output.should(match(/#{regex}/)) : + actual_output.should_not(match(/#{regex}/)) end Then /^all (\d+) tests pass$/ do |expected_test_count| expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors} actual_output = File.read(@stdout) @@ -190,10 +193,10 @@ actual_output = File.read(@rake_stdout) actual_output.should match(/^rake\s+\w+\s+#\s.*/) end Then /^task 'rake (.*)' is executed successfully$/ do |task| - @raketask_stdout.should_not be_nil - actual_output = File.read(@raketask_stdout) + @stdout.should_not be_nil + actual_output = File.read(@stdout) actual_output.should_not match(/^Don't know how to build task '#{task}'/) actual_output.should_not match(/Error/i) end \ No newline at end of file