1
votes

I am new to Rails and TDD and am stuck at a transition between Rspec testing and Cucumber testing. My Rspec tests all pass green:

  ModelController
    Find with same attribute
      should call the controller method that performs attribute search
      should select the Search Results template for rendering
      should make the attribute search results available to that template

So I return to my Cucumber feature:

  When I follow "Find Items With Same Attribute"              
  Then I should be on the Similar Items page for "Attribute"

The first one goes green if I include this in my view:

  = link_to "Find Items With Same Attribute"

For the second one, I modify my paths.rb file to contain:

  when /^the Similar Items page for "(.*)"/
    "/model/search_by_attribute/#{Model.find_by_name($1).attribute}"

And then it fails with this error

   expected: "/model/search_by_attribute/Attribute"
             got: "/model/1" (using ==) (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/web_steps.rb:233:in `/^(?:|I )should be on (.+)$/'
      features/search_by_attribute.feature:25:...

If I include a step definition in model_steps.rb I get a different error:

Ambiguous match of "I should be on the Similar Items page for "Attribute"":

features/step_definitions/model_steps.rb:11:in `/^(?:|I )should be on the (.+) page for "(.*)"$/'
features/step_definitions/web_steps.rb:230:in `/^(?:|I )should be on (.+)$/'

Do I need to finish the route in the view? Do I need to write a step definition that will not be ambiguous? I don't know how to proceed from here, and any suggestions would be much appreciated.

1

1 Answers

1
votes

My guess is that you need to finish the link_to method you created. Cucumber does high level testing so it will click that link and follow it. Since you haven't specified a path its probably keeping you at your current page, rather then taking you to the Similar Items page.