Spec'ing via features

On Tue, Nov 25, 2008 at 4:06 PM, James B. [email protected]
wrote:

Forgive my misapprehension.

So, where does one find a comprehensive list of expectations for
cucumber step matchers? Things like:

response.body.should +~ \pattern\

Cucumber doesn’t supply those. You can use whatever tool you want to
do the job. RSpec, test/unit, assert 2.0, etc… could all be used. You
may have to include something into “World” to get the methods
available from your tool of choice, but I use RSpec and haven’t had to
do that (just guessing)…


Zach D.
http://www.continuousthinking.com

James B. wrote:

Aslak Hellesøy wrote:

Cucumber depends upon RSpec.

No it doesn’t

Aslak

Forgive my misapprehension.

However, this is what rdoc says:

cucumber 0.1.9 [rdoc] [www] - depends on diff-lcs, hoe, rspec,
term-ansicolor, treetop.

Ben M. wrote:

The previous gem releases of cucumber required the rspec gem but as of a
few commits ago that dependency is only there for developing cucumber.

-Ben

I see. So, if I understand correctly, rspec is the “default” testing
framework? But, if one wished to incorporate minitest say, then one
would extend the cucumber world (a concept that I have only the vaguest
conception of) in a manner similar to this?

require ‘minitest/unit/assertions’
World do |o|
o.extend(MiniTest::Unit::Assertions)
o
end

Zach D. wrote:

Cucumber doesn’t supply those. You can use whatever tool you want to
do the job. RSpec, test/unit, assert 2.0, etc… could all be used. You
may have to include something into “World” to get the methods
available from your tool of choice, but I use RSpec and haven’t had to
do that (just guessing)…

Cucumber has some examples on how to use other testing frameworks:
http://github.com/aslakhellesoy/cucumber/tree/89c56b13f09d5293b738c3f3feb0ed08af8a43ce/examples%2Ftest_unit%2Ffeatures%2Fstep_definitions%2Ftest_unit_steps.rb

The previous gem releases of cucumber required the rspec gem but as of a
few commits ago that dependency is only there for developing cucumber.

-Ben

James B. wrote:

But, if one wished to incorporate minitest say, then one
would extend the cucumber world

Where does one put this? A the begining of each step_definitions file?
In support/env.rb?

James B. wrote:

framework? But, if one wished to incorporate minitest say, then one
would extend the cucumber world (a concept that I have only the vaguest
conception of) in a manner similar to this?

require ‘minitest/unit/assertions’
World do |o|
o.extend(MiniTest::Unit::Assertions)
o
end

Right. Although, I’m unsure if rspec is even the default framework
outside of the rails generators.
-Ben

Ben M. wrote:

Right. Although, I’m unsure if rspec is even the default framework
outside of the rails generators.
-Ben

Where can one get a handy quick reference of what syntax is acceptable
to cucumber by default?

James B. wrote:

James B. wrote:

But, if one wished to incorporate minitest say, then one
would extend the cucumber world

Where does one put this? A the begining of each step_definitions file?
In support/env.rb?

You only need it once- so the env.rb file is fine and natural place for
it.

James B. wrote:

Hmm… I’m not sure what you mean but the cucumber wiki is the best
place:

-Ben

On Tue, Nov 25, 2008 at 9:54 PM, James B. [email protected]
wrote:

Aslak Hellesøy wrote:

Cucumber depends upon RSpec.

No it doesn’t

Aslak

Forgive my misapprehension.

Sorry - I should never email from my iPhone.

What I meant is that Cucumber itself does not have any dependencies on
RSpec. However, your own step definitions can use RSpec’s Rails
extensions
if you require cucumber/rails/rspec. Most Cucumber/Rails users seem to
be
doing this although there are no hard dependencies. If you only require
cucumber/rails/world you can just use regular Rails integration testing
APIs
in your step definitions.

I hope this clarifies a little more.

Cheers,
Aslak

Since Cucumber is about BDD and defining the “acceptable and desired
behavior” of the software through plain english (executable
requirements if you will) it is not always clear what “level” the
steps will implement.

In the case of Rails testing out of the box this maps roughly to:

  1. unit tests - models
  2. functional tests - controllers
  3. integration tests - multiple controllers/models

In Cucumber we’re not really drawing those lines so clearly and tests
will draw on some or more of each of these levels.

Is this accurate?

Thanks,

Tim

On Tue, Nov 25, 2008 at 6:09 PM, Tim W. [email protected] wrote:

In Cucumber we’re not really drawing those lines so clearly and tests
will draw on some or more of each of these levels.

Is this accurate?

The general recommendation is that Cucumber replaces rails integration
tests and RSpec replaces rails functional and unit tests.

HTH,
David

James B. [email protected] writes:

Ben M. wrote:

Right. Although, I’m unsure if rspec is even the default framework
outside of the rails generators.
-Ben

Where can one get a handy quick reference of what syntax is acceptable
to cucumber by default?

Ruby syntax is acceptable

Pat

Great post James. Very, helpful. Perhaps should be on the cucumber
Wiki? I hope someone follows up on the load fixtures question. Lots to
go play with now!!! Tim

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.

No arguments there! Just curious why it didn’t work…

FWIW - I just did it and it seemed OK…

/features/steps/holiday_steps.rb

Then /^there should be 2 nodes in the control group$/ do
Fixtures.create_fixtures("/…/…/test/fixtures", “holiday_schedules”)
end

/test/fixtures/holiday_schedules.yml
one:
for_year: 2020

No moaning from Cucumber though it complained as I was getting the
path and table name right. YMMV.

Thanks again, very much.

Tim

Tim W. wrote:

FWIW - I just did it and it seemed OK…

/features/steps/holiday_steps.rb

Then /^there should be 2 nodes in the control group$/ do
Fixtures.create_fixtures("/…/…/test/fixtures", “holiday_schedules”)
end

/test/fixtures/holiday_schedules.yml
one:
for_year: 2020

No moaning from Cucumber though it complained as I was getting the
path and table name right. YMMV.

That is probably my problem. I did not pass it the correct path and
file name so the reason the fixture was not loaded was because it did
not exist.

Fixtures = yuk!!

Try object_daddy or maybe factory_girl instead :slight_smile:

Andrew

2008/11/26 Tim W. [email protected]: