Tim W. wrote:
Question: In Cucumber when you’re writing code to satisfy steps and
accessing the model objects directly, what support for asserts,
responses, etc.
do people use. (the equivalent of ActionController::TestCase and
ActiveSupport::TestCase), Fixtures, etc.
Thanks,
T
This question prompted a really interesting journey through cucumber for
me. I now have a much firmer, if still very limited, grasp of what is
happening.
When one uses “ruby script/generate cucumber” at the rails project root
then the script generates (among other things) a features/support/env.rb
file. This file contains (in part):
require ‘cucumber/rails/world’
require ‘cucumber/rails/rspec’
The cucumber gem location lib/cucumber/rails/rspec contains
rspec.rb
world.rb
and rspec.rb has this:
require ‘spec’
require ‘spec/rails’
Next, world.rb makes a conditional reference (almost universally met in
a Rails project - Do you use ActiveRecord?) to testunit via
/usr/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/test_help.rb. Now that file
contains:
require ‘test/unit’
require ‘active_support/test_case’
require ‘active_record/fixtures’
require ‘action_controller/test_case’
require ‘action_controller/integration’
require ‘action_mailer/test_case’ if defined?(ActionMailer)
So, it appears that when you generate the cucumber infrastructure via
the rails generator then you get rspec ‘should’ ‘should_not’ and rails
testunit assert_* support. As previously discussed in this thread,
adding other testing harnesses is a fairly straight forward procedure
best done in the aforementioned support/env.rb. For example, adding
watir gem support is done via this:
require ‘webrat’ if !defined?(Webrat)
I gather from allusions made elsewhere that if watir is installed as a
plugin within the rail project then it gets picked up automatically and
the default watir.steps generated by the rails generator work without
further modification to the env.rb file.
I was unable to discover how to employ fixtures. I found and read this
thread: Cucumber and fixtures - RSpec - Ruby-Forum but the final
recommendation “Fixtures.create_fixtures(“spec/fixtures”, “entities”)”
did not work for me. It did not raise an error but it did not load the
fixture either. The TestUnit syntax of “fixtures :model” throws an
undefined method error which is passing strange given test_help.rb’s
require ‘active_record/fixtures’. Nonetheless, TestUnit syntax like
assert_something(argument,…argument,message) works fine.
Anyway, a most enlightening code crawl.