Hi all,
i wrote a Rspec test for my controller and it fails although it should pass.
Here is my Rspec test:

require 'spec_helper'

describe UsersController do
render_views

describe "GET 'show'" do
it "returns http success" do
get 'show'
response.should be_success
end

it "should have the right title" do
get 'show'
response.should have_selector("title",:content => " | User")
end
end

end


The test fails with this message:

Failures:

1) UsersController GET 'show' returns http success
Failure/Error: get 'show'
ActionController::RoutingError:
No route matches {:controller=>"users", :action=>"show"}
# ./spec/controllers/users_controller_spec.rb:20:in `block (3 levels) in <top (required)>'

2) UsersController GET 'show' should have the right title
Failure/Error: get 'show'
ActionController::RoutingError:
No route matches {:controller=>"users", :action=>"show"}
# ./spec/controllers/users_controller_spec.rb:25:in `block (3 levels) in <top (required)>'

The controller is already created also the view. I got the method show in the users controller. I also added the resources :users to my routes.rb.
I am able to reach the page without problems. I also checked the rake routes and they are available for this test so it should go green.

Maybe someone see an error and can help me out with this. It would be great.

Thanks and regards

Greg

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Dave Aronson at Nov 7, 2011 at 8:59 pm

    On Mon, Nov 7, 2011 at 15:49, Gregor Panek wrote:

    describe "GET 'show'" do
    it "returns http success" do
    get 'show'
    response.should be_success
    end
    Don't you need to specify an id there? Or are you thinking "index"
    (show *all*)?

    -Dave

    --
    LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
    Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
    See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
    Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Gregor Panek at Nov 7, 2011 at 9:11 pm

    Am 07.11.2011 um 21:58 schrieb Dave Aronson:
    On Mon, Nov 7, 2011 at 15:49, Gregor Panek wrote:

    describe "GET 'show'" do
    it "returns http success" do
    get 'show'
    response.should be_success
    end
    Don't you need to specify an id there? Or are you thinking "index"
    (show *all*)?

    -Dave

    --
    LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
    Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
    See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
    Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

    How to do that? I just started to learn how write tests for the application.

    describe "GET 'show'" do
    it "returns http success" do
    get 'show/1'
    response.should be_success
    end

    OR can i use a wildcard?

    describe "GET 'show'" do
    it "returns http success" do
    get 'show/:id'
    response.should be_success
    end


    What makes me pondering is that rake routes is shows that the route is available so how can the id be the problem that the test fails?! Sorry if this question is stupid but I'm still in the learning stage

    users GET /users(.:format) {:action=>"index", :controller=>"users"}
    POST /users(.:format) {:action=>"create", :controller=>"users"}
    new_user GET /users/new(.:format) {:action=>"new", :controller=>"users"}
    edit_user GET /users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
    user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
    PUT /users/:id(.:format) {:action=>"update", :controller=>"users"}
    DELETE /users/:id(.:format) {:action=>"destroy", :controller=>"users"}


    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Dave Aronson at Nov 7, 2011 at 9:23 pm

    On Mon, Nov 7, 2011 at 16:11, Gregor Panek wrote:

    Am 07.11.2011 um 21:58 schrieb Dave Aronson:
    Don't you need to specify an id there?
    How to do that? I just started to learn how write tests for the application.
    I recommend you read:

    http://guides.rubyonrails.org/testing.html

    (and then all the other assorted Rails Guides). To get you started,
    it contains this snippet that might be helpful:

    Example: Calling the :show action, passing an id of 12 as the params
    and setting a user_id of 5 in the session:
    get(:show, {'id' => "12"}, {'user_id' => 5})

    Another example: Calling the :view action, passing an id of 12 as
    the params, this time with no session, but with a flash message.
    get(:view, {'id' => '12'}, nil, {'message' => 'booya!'})

    So for your purposes, I'd think that:

    get :show, :id => '1'

    might do fine, assuming that there is indeed a user with ID 1 in your
    test database.
    What makes me pondering is that rake routes
    is shows that the route is available
    Right, but if you look at that line:
    user GET   /users/:id(.:format)   {:action=>"show", :controller=>"users"}
    you see ":id", which means you need to supply that somehow. (The
    :format part is in parens, meaning it's optional.)
    Sorry if this question is stupid but I'm still in the learning stage
    No problem, we all started there too. :-) Kudos to you for testing
    at all, many people skip that entirely! :-(

    -Dave

    --
    LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
    Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
    See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
    Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Gregor Panek at Nov 7, 2011 at 10:02 pm

    Am 07.11.2011 um 22:22 schrieb Dave Aronson:
    On Mon, Nov 7, 2011 at 16:11, Gregor Panek wrote:

    Am 07.11.2011 um 21:58 schrieb Dave Aronson:
    Don't you need to specify an id there?
    How to do that? I just started to learn how write tests for the application.
    I recommend you read:

    http://guides.rubyonrails.org/testing.html

    (and then all the other assorted Rails Guides). To get you started,
    it contains this snippet that might be helpful:

    Example: Calling the :show action, passing an id of 12 as the params
    and setting a user_id of 5 in the session:
    get(:show, {'id' => "12"}, {'user_id' => 5})

    Another example: Calling the :view action, passing an id of 12 as
    the params, this time with no session, but with a flash message.
    get(:view, {'id' => '12'}, nil, {'message' => 'booya!'})

    So for your purposes, I'd think that:

    get :show, :id => '1'

    might do fine, assuming that there is indeed a user with ID 1 in your
    test database.
    Thanks for the link i will start reading the tutorials. For now your posted proposal worked, after i added some data to the test database (is easy to forget)
    What makes me pondering is that rake routes
    is shows that the route is available
    Right, but if you look at that line:
    user GET /users/:id(.:format) {:action=>"show", :controller=>"users"}
    you see ":id", which means you need to supply that somehow. (The
    :format part is in parens, meaning it's optional.)
    You are right my method will only work for static routes or routes like index, new
    Sorry if this question is stupid but I'm still in the learning stage
    No problem, we all started there too. :-) Kudos to you for testing
    at all, many people skip that entirely! :-(
    Nice to hear that :)

    Thanks for your help

    Regards Greg
    -Dave

    --
    LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
    Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
    See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
    Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 7, '11 at 8:50p
activeNov 7, '11 at 10:02p
posts5
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Gregor Panek: 3 posts Dave Aronson: 2 posts

People

Translate

site design / logo © 2021 Grokbase