Forum: RSpec how to deal with redirect_to on cucumber?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ffd881829651935d986c52d12279befb?d=identicon&s=25 Zhenning Guan (rubyernewbie)
on 2009-05-20 17:43
I have a controller name forums and a action like this:
  def show
     redirect_to forum_topics_path(:forum_id => params[:id])
  end

my scenario is (not completed)
==========
Scenario: User input data correct
  When I run to the forum 1

--
When /^I run to the (.*)$/ do |topic_lists|
  visit path_to(topic_lists)
end

 def path_to(page_name)
    case page_name

    when /forum 1/
      forum_path(1)
==========

when I runned rake features
got a error..
++++++++++++++++
 Scenario: User input data correct # features/forums.feature:10
    When I run to the topic lists   #
features/step_definitions/forums_steps.rb:10
      Couldn't find Forum with ID=1 (ActiveRecord::RecordNotFound)
      /home/ning/blank/app/controllers/topics_controller.rb:71:in
`load_forum'
      /usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
      (eval):2:in `/^I run to the (.*)$/'
      features/forums.feature:11:in `When I run to the topic lists'
++++++++++++++++++

so is that redirect_to problems? how to implement the scenario? any
thought here?
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-05-21 09:41
(Received via mailing list)
On 20 May 2009, at 16:43, Zhenning Guan wrote:

> --
>
>      (eval):2:in `/^I run to the (.*)$/'
>      features/forums.feature:11:in `When I run to the topic lists'
> ++++++++++++++++++
>
> so is that redirect_to problems? how to implement the scenario? any
> thought here?

You are trying to visit the page for a 'forum' object (with ID=1) that
does not exist in your database.

In each scenario, you need to imagine your application starts from a
completely empty state, just like it would if you started the
application with script/server.

You need a step in your scenario that says 'Given there is a Forum'
which creates the record in the database.

If you don't mind me saying so, this question suggests to me that you
have quite a bit to learn about Cucumber. While people on this list
are pretty patient and helpful, they are also busy and will be more
keen to help if you spend some time helping yourself too. I suggest
you start with the recent railscast on Cucumber.

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-05-21 11:24
(Received via mailing list)
Instead of answering Cucumber questions on this list, please redirect
people to the new one:

http://www.nabble.com/-Cucumber--ANN%3A-New-Google...

Aslak
This topic is locked and can not be replied to.