From ded39bc05fb28db601069e4ff5ac84d432443c7e Mon Sep 17 00:00:00 2001 From: Jesse Bounds and Tim Jarratt Date: Thu, 5 Dec 2013 15:06:12 -0800 Subject: [PATCH] DRY up the cucumber step definitions --- .../scenario_steps/ios_templates_steps.rb | 44 ------------------- .../scenario_steps/osx_templates_steps.rb | 41 ----------------- .../step_definitions/modify_target_steps.rb | 7 +++ features/step_definitions/rake_steps.rb | 17 +++++++ features/step_definitions/xcode_steps.rb | 12 +++++ 5 files changed, 36 insertions(+), 85 deletions(-) delete mode 100644 features/scenario_steps/ios_templates_steps.rb delete mode 100644 features/scenario_steps/osx_templates_steps.rb create mode 100644 features/step_definitions/modify_target_steps.rb create mode 100644 features/step_definitions/rake_steps.rb create mode 100644 features/step_definitions/xcode_steps.rb diff --git a/features/scenario_steps/ios_templates_steps.rb b/features/scenario_steps/ios_templates_steps.rb deleted file mode 100644 index 44529cb6..00000000 --- a/features/scenario_steps/ios_templates_steps.rb +++ /dev/null @@ -1,44 +0,0 @@ -Given(/^an Xcode iOS project$/) do - `rm -rf template-project` - `cp -pr features/support/ios-project-template template-project` - $?.exitstatus.should == 0 - File.exist?("template-project").should be_true -end - -When(/^I add an iOS Spec bundle target$/) do - `open -a Xcode template-project/template-project.xcodeproj` - `osascript features/support/scripts/ios_add_spec_bundle.scpt` - File.exist?("template-project/Specs").should be_true -end - -When(/^I add an iOS Spec suite target$/) do - `open -a Xcode template-project/template-project.xcodeproj` - `osascript features/support/scripts/ios_add_spec_suite.scpt` - File.exist?("template-project/Specs").should be_true -end - -When(/^I reference AppDelegate in the test$/) do - `cp features/support/templates/ExampleSpec.mm template-project/Specs` -end - -When(/^I add a failing test$/) do - `cp features/support/templates/FailingSpec.mm template-project/Specs/ExampleSpec.mm` -end - -Then(/^the `rake Specs` should work$/) do - Dir.chdir('template-project/Specs') do - output = `rake Specs 2> /dev/null` - if $? != 0 - puts "!!! Spec target failed. Build output:" - puts output - end - $?.exitstatus.should eq(0) - end -end - -Then(/^running the specs from the rake task should fail$/) do - Dir.chdir('template-project/Specs') do - `rake Specs 2> /dev/null` - $?.exitstatus.should_not eq(0) - end -end diff --git a/features/scenario_steps/osx_templates_steps.rb b/features/scenario_steps/osx_templates_steps.rb deleted file mode 100644 index 32d0b9b1..00000000 --- a/features/scenario_steps/osx_templates_steps.rb +++ /dev/null @@ -1,41 +0,0 @@ -Given(/^an Xcode OS X project$/) do - `rm -rf template-project` - `cp -pr features/support/osx-project-template template-project` - $?.exitstatus.should == 0 - File.exist?("template-project").should be_true -end - -When(/^I add an OS X Spec bundle target$/) do - `open -a Xcode template-project/template-project.xcodeproj` - `osascript features/support/scripts/osx_add_spec_bundle.scpt` - File.exist?("template-project/Specs").should be_true -end - -When(/^I add an OS X Spec suite target$/) do - `open -a Xcode template-project/template-project.xcodeproj` - `osascript features/support/scripts/osx_add_spec_suite.scpt` - File.exist?("template-project/Specs").should be_true -end - -When(/^I add a failing test$/) do - `cp features/support/templates/FailingSpec.mm template-project/Specs/ExampleSpec.mm` -end - -Then(/^the `rake Specs` should work$/) do - Dir.chdir('template-project/Specs') do - output = `rake Specs 2> /dev/null` - if $? != 0 - puts "!!! Spec target failed. Build output:" - puts output - end - $?.exitstatus.should == 0 - end -end - -Then(/^running the specs from the rake task should fail$/) do - Dir.chdir('template-project/Specs') do - `rake Specs 2> /dev/null` - $?.exitstatus.should_not eq(0) - end -end - diff --git a/features/step_definitions/modify_target_steps.rb b/features/step_definitions/modify_target_steps.rb new file mode 100644 index 00000000..a091c74e --- /dev/null +++ b/features/step_definitions/modify_target_steps.rb @@ -0,0 +1,7 @@ +When(/^I add a failing test$/) do + `cp features/support/templates/FailingSpec.mm template-project/Specs/ExampleSpec.mm` +end + +When(/^I reference AppDelegate in the test$/) do + `cp features/support/templates/ExampleSpec.mm template-project/Specs` +end diff --git a/features/step_definitions/rake_steps.rb b/features/step_definitions/rake_steps.rb new file mode 100644 index 00000000..d2889a8a --- /dev/null +++ b/features/step_definitions/rake_steps.rb @@ -0,0 +1,17 @@ +Then(/^the `rake Specs` should work$/) do + Dir.chdir('template-project/Specs') do + output = `rake Specs 2> /dev/null` + if $? != 0 + puts "!!! Spec target failed. Build output:" + puts output + end + $?.exitstatus.should eq(0) + end +end + +Then(/^running the specs from the rake task should fail$/) do + Dir.chdir('template-project/Specs') do + `rake Specs 2> /dev/null` + $?.exitstatus.should_not eq(0) + end +end diff --git a/features/step_definitions/xcode_steps.rb b/features/step_definitions/xcode_steps.rb new file mode 100644 index 00000000..6af131e0 --- /dev/null +++ b/features/step_definitions/xcode_steps.rb @@ -0,0 +1,12 @@ +When(/^I add an (iOS|OS X) Spec (suite|bundle) target$/) do |os, target_type| + `open -a Xcode template-project/template-project.xcodeproj` + `osascript features/support/scripts/#{os.downcase.gsub(/\s+/, '')}_add_spec_#{target_type.downcase.gsub(/\s+/, '')}.scpt` + File.exist?("template-project/Specs").should be_true +end + +Given(/^an Xcode (iOS|OS X) project$/) do |os| + `rm -rf template-project` + `cp -pr features/support/#{os.downcase.gsub(/\s+/, '')}-project-template template-project` + $?.exitstatus.should == 0 + File.exist?("template-project").should be_true +end