Skip to content

Commit

Permalink
converted all steps %r{...} to classic /.../ regexps
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Mar 17, 2009
1 parent 8c2e819 commit 429c869
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 56 deletions.
3 changes: 3 additions & 0 deletions Manifest.txt
Expand Up @@ -43,6 +43,8 @@ features/rubygem_tasks.feature
features/step_definitions/cli_steps.rb
features/step_definitions/common_steps.rb
features/step_definitions/rubygems_steps.rb
features/support/cli.rb
features/support/common.rb
features/support/env.rb
lib/hoe-patched.rb
lib/newgem.rb
Expand Down Expand Up @@ -91,6 +93,7 @@ rubygems_generators/install_cucumber/USAGE
rubygems_generators/install_cucumber/install_cucumber_generator.rb
rubygems_generators/install_cucumber/templates/features/development.feature
rubygems_generators/install_cucumber/templates/features/step_definitions/common_steps.rb
rubygems_generators/install_cucumber/templates/features/support/common.rb
rubygems_generators/install_cucumber/templates/features/support/env.rb.erb
rubygems_generators/install_jruby/USAGE
rubygems_generators/install_jruby/install_jruby_generator.rb
Expand Down
16 changes: 8 additions & 8 deletions features/step_definitions/cli_steps.rb
@@ -1,4 +1,4 @@
Given %r{^an existing newgem scaffold \[called '(.*)'\]} do |project_name|
Given /^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
Expand All @@ -9,7 +9,7 @@
end
end

Given %r{^an existing newgem scaffold using options '(.*)' \[called '(.*)'\]} do |arguments, project_name|
Given /^an existing newgem scaffold using options '(.*)' \[called '(.*)'\]/ do |arguments, project_name|
Given "a safe folder"
newgem = File.expand_path(File.dirname(__FILE__) + "/../../bin/newgem")
setup_active_project_folder project_name
Expand All @@ -20,7 +20,7 @@
end
end

Given %r{^project website configuration for safe folder on local machine$} do
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
FileUtils.mkdir_p @remote_folder
Expand All @@ -32,7 +32,7 @@
end
end

Given %r{^~\/([^\s]+) contains (\{.*\})$} do |file, config|
Given /^~\/([^\s]+) contains (\{.*\})$/ do |file, config|
in_home_folder do
File.open(file, 'w') do |f|
yaml = eval(config)
Expand All @@ -41,7 +41,7 @@
end
end

When %r{^newgem is executed for project '(.*)' with no options$} do |project_name|
When /^newgem is executed for project '(.*)' with no options$/ do |project_name|
@newgem_cmd = newgem_cmd
setup_active_project_folder project_name
in_tmp_folder do
Expand All @@ -51,7 +51,7 @@
end
end

When %r{^newgem is executed for project '(.*)' with options '(.*)'$} do |project_name, arguments|
When /^newgem is executed for project '(.*)' with options '(.*)'$/ do |project_name, arguments|
@newgem_cmd = newgem_cmd
setup_active_project_folder project_name
in_tmp_folder do
Expand All @@ -77,13 +77,13 @@
end
end

Then %r{^remote folder '(.*)' is created} do |folder|
Then /^remote folder '(.*)' is created/ do |folder|
FileUtils.chdir @remote_folder do
File.exists?(folder).should be_true
end
end

Then %r{^remote file '(.*)' (is|is not) created} do |file, is|
Then /^remote file '(.*)' (is|is not) created/ do |file, is|
FileUtils.chdir @remote_folder do
File.exists?(file).should(is == 'is' ? be_true : be_false)
end
Expand Down
48 changes: 24 additions & 24 deletions features/step_definitions/common_steps.rb
@@ -1,27 +1,27 @@
Given %r{^a safe folder} do
Given /^a safe folder/ do
FileUtils.rm_rf @tmp_root = File.dirname(__FILE__) + "/../../tmp"
FileUtils.mkdir_p @tmp_root
FileUtils.mkdir_p @home_path = File.expand_path(File.join(@tmp_root, "home"))
@lib_path = File.expand_path(File.dirname(__FILE__) + '/../../lib')
Given "env variable $HOME set to '#{@home_path}'"
end

Given %r{^this project is active project folder} do
Given /^this project is active project folder/ do
Given "a safe folder"
@active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
end

Given %r{^env variable \$([\w_]+) set to '(.*)'} do |env_var, value|
Given /^env variable \$([\w_]+) set to '(.*)'/ do |env_var, value|
ENV[env_var] = value
end

Given %r{'(.*)' folder is deleted} do |folder|
Given /'(.*)' folder is deleted/ do |folder|
in_project_folder do
FileUtils.rm_rf folder
end
end

When %r{^'(.*)' generator is invoked with arguments '(.*)'$} do |generator, arguments|
When /^'(.*)' generator is invoked with arguments '(.*)'$/ do |generator, arguments|
@stdout = StringIO.new
FileUtils.chdir(@active_project_folder) do
if Object.const_defined?("APP_ROOT")
Expand All @@ -37,88 +37,88 @@
end
end

When %r{run executable '(.*)' with arguments '(.*)'} do |executable, arguments|
When /run executable '(.*)' with arguments '(.*)'/ do |executable, arguments|
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
in_project_folder do
system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
end
end

When %r{run project executable '(.*)' with arguments '(.*)'} do |executable, arguments|
When /run project executable '(.*)' with arguments '(.*)'/ do |executable, arguments|
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
in_project_folder do
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
end
end

When %r{run local executable '(.*)' with arguments '(.*)'} do |executable, arguments|
When /run local executable '(.*)' with arguments '(.*)'/ do |executable, arguments|
@stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
in_project_folder do
system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
end
end

When %r{^task 'rake (.*)' is invoked$} do |task|
When /^task 'rake (.*)' is invoked$/ do |task|
@stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
FileUtils.chdir(@active_project_folder) do
system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
end
end

Then %r{^folder '(.*)' (is|is not) created} do |folder, is|
Then /^folder '(.*)' (is|is not) created/ do |folder, is|
in_project_folder do
File.exists?(folder).should(is == 'is' ? be_true : be_false)
end
end

Then %r{^file '(.*)' (is|is not) created} do |file, is|
Then /^file '(.*)' (is|is not) created/ do |file, is|
in_project_folder do
File.exists?(file).should(is == 'is' ? be_true : be_false)
end
end

Then %r{^file with name matching '(.*)' is created} do |pattern|
Then /^file with name matching '(.*)' is created/ do |pattern|
in_project_folder do
Dir[pattern].should_not be_empty
end
end

Then %r{gem file '(.*)' and generated file '(.*)' should be the same} do |gem_file, project_file|
Then /gem file '(.*)' and generated file '(.*)' should be the same/ do |gem_file, project_file|
File.exists?(gem_file).should be_true
File.exists?(project_file).should be_true
gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
project_file_contents = File.read(File.join(@active_project_folder, project_file))
project_file_contents.should == gem_file_contents
end

Then %r{^output same as contents of '(.*)'$} do |file|
Then /^output same as contents of '(.*)'$/ do |file|
expected_output = File.read(File.join(File.dirname(__FILE__) + "/../expected_outputs", file))
actual_output = File.read(@stdout)
actual_output.should == expected_output
end

Then %r{^(does|does not) invoke generator '(.*)'$} do |does_invoke, generator|
Then /^(does|does not) invoke generator '(.*)'$/ do |does_invoke, generator|
actual_output = File.read(@stdout)
does_invoke == "does" ?
actual_output.should(match(/dependency\s+#{generator}/)) :
actual_output.should_not(match(/dependency\s+#{generator}/))
end

Then %r{help options '(.*)' and '(.*)' are displayed} do |opt1, opt2|
Then /help options '(.*)' and '(.*)' are displayed/ do |opt1, opt2|
actual_output = File.read(@stdout)
actual_output.should match(/#{opt1}/)
actual_output.should match(/#{opt2}/)
end

Then %r{^output (does|does not) match \/(.*)\/} do |does, regex|
Then /^output (does|does not) match \/(.*)\// do |does, regex|
actual_output = File.read(@stdout)
(does == 'does') ?
actual_output.should(match(/#{regex}/)) :
actual_output.should_not(match(/#{regex}/))
end

Then %r{^contents of file '(.*)' (does|does not) match \/(.*)\/} do |file, does, regex|
Then /^contents of file '(.*)' (does|does not) match \/(.*)\// do |file, does, regex|
in_project_folder do
actual_output = File.read(file)
(does == 'does') ?
Expand All @@ -127,26 +127,26 @@
end
end

Then %r{^all (\d+) tests pass} do |expected_test_count|
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)
actual_output.should match(expected)
end

Then %r{^all (\d+) examples pass} do |expected_test_count|
Then /^all (\d+) examples pass/ do |expected_test_count|
expected = %r{^#{expected_test_count} examples?, 0 failures}
actual_output = File.read(@stdout)
actual_output.should match(expected)
end

Then %r{^yaml file '(.*)' contains (\{.*\})} do |file, yaml|
Then /^yaml file '(.*)' contains (\{.*\})/ do |file, yaml|
in_project_folder do
yaml = eval yaml
YAML.load(File.read(file)).should == yaml
end
end

Then %r{^Rakefile can display tasks successfully} do
Then /^Rakefile can display tasks successfully/ do
@stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
FileUtils.chdir(@active_project_folder) do
system "rake -T > #{@stdout} 2> #{@stdout}"
Expand All @@ -155,14 +155,14 @@
actual_output.should match(/^rake\s+\w+\s+#\s.*/)
end

Then %r{^task 'rake (.*)' is executed successfully} do |task|
Then /^task 'rake (.*)' is executed successfully/ do |task|
@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

Then %r{^gem spec key '(.*)' contains \/(.*)\/} do |key, regex|
Then /^gem spec key '(.*)' contains \/(.*)\// do |key, regex|
in_project_folder do
gem_file = Dir["pkg/*.gem"].first
gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
Expand Down

0 comments on commit 429c869

Please sign in to comment.