The folks here have given me the task of figuring out if cucumber can
be used successfully to test some of our apps.
I have the latest versions of rails, mechanize, cucumber webrat and
rspec installed.
#/cuketest/features/google.feature
Feature: New PC
In order to get a sweet new PC
As a apple nerd
I want to find apple.com
Scenario: Get a sweet new computer
Given I visit "http://www.google.com"
When I fill in "q" with "apple"
And I press "Google Search"
Then I should see "www.apple.com"
#/cuketest/features/support/env.rb
#...
Webrat.configure do |config|
config.mode = :mechanize
end
#...
class MechanizeWorld < Webrat::MechanizeSession
require ''spec''
include Spec::Matchers
end
#...
#/cuketest/features/support/paths.rb
module NavigationHelpers
# Maps a name to a path. Used by the
#
# When /^I go to (.+)$/ do |page_name|
#
# step definition in webrat_steps.rb
#
def path_to(page_name)
case page_name
when /the homepage/
''/''
# Add more mappings here.
# Here is a more fancy example:
#
# when /^(.*)''s profile page$/i
# user_profile_path(User.find_by_login($1))
else
raise "Can''t find mapping from \"#{page_name}\" to
a path.\n" +
"Now, go and add a mapping in #{__FILE__}"
end
end
end
World(NavigationHelpers)[/code]
This is not complete however. If I run rake features at this point, I
get an error saying it doesn''t understand the visit command in the
step (which i assume comes from Mechanize)
The various information around the internet points to me needing to
add this to the world:
[code=]World do
MechanizeWorld.new
end[/code]
Adding this block gives me the following error:
c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.2/bin/../lib/cucumber/
step_mother.rb:195:in `World'': You can only pass a pro
c to #World once, but it''s happening (Cucumber::MultipleWorld)
in 2 places:
ls/world.rb:84:in `World''
features/support/paths.rb:26:in `World''
Use Ruby modules instead to extend your worlds. See the
Cucumber::StepMother#World RDoc
or http://wiki.github.com/aslakhellesoy/cucumber/a-whole-new-world.
from ./features/support/paths.rb:26
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
31:in `gem_original_require''
from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
31:in `polyglot_original_require''
from c:/ruby/lib/ruby/gems/1.8/gems/polyglot-0.2.5/lib/
polyglot.rb:54:in `require''
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/
active_support/dependencies.rb:158:in `require''
from c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.2/bin/../lib/
cucumber/cli/main.rb:79:in `require_files''
from c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.2/bin/../lib/
cucumber/cli/main.rb:77:in `each''
from c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.2/bin/../lib/
cucumber/cli/main.rb:77:in `require_files''
from c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.2/bin/../lib/
cucumber/cli/main.rb:34:in `execute!''
from c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.2/bin/../lib/
cucumber/cli/main.rb:20:in `execute''
from c:/ruby/lib/ruby/gems/1.8/gems/cucumber-0.3.2/bin/
cucumber:6
rake aborted!
Command failed with status (1): [c:/ruby/bin/ruby -I "c:/ruby/lib/ruby/
gems...]
(See full trace by running task with --trace)
So if I have to use a module to extend the world (even though the
documentation seems to point at this being right) how do I go about
doing this?