Hi all,

I'm trying to test that my users show page renders. The resource has
the route /users/:id

How would I code that for an Rspec test? So far I've tried these four
ways:

it "should have a users show path" do
get user_path(:action => 'show')
end

it "should have a users show path" do
get user_show_path
end

it "should have a users show path" do
get user_path(:id => '1')
end

it "should have a users show path" do
get '/users/1'
end

But I keep getting a RoutingError from Rspec even though it renders ok
when I just go to the page. So how would I spec it? Thanks

--
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

  • Peter Vandenabeele at Feb 6, 2012 at 10:02 am

    On Mon, Feb 6, 2012 at 12:16 AM, edward michaels wrote:

    Hi all,

    I'm trying to test that my users show page renders. The resource has
    the route /users/:id

    How would I code that for an Rspec test? So far I've tried these four
    ways:

    it "should have a users show path" do
    get user_path(:action => 'show')
    end

    it "should have a users show path" do
    get user_show_path
    end

    it "should have a users show path" do
    get user_path(:id => '1')
    end
    This variant worked on my side:

    ../spec/requests$ vim orders_spec.rb
    describe "Orders" do
    ...
    describe "GET /order/id" do
    it "routes to a show order" do
    get order_path(:id => "abc123")
    response.status.should be(200)
    end
    end

    Passes when that order is in the test db and fails with
    ActiveRecord::RecordNotFound when I change
    the id to a non-present value, so that seems correct.
    I have the record in the test db at the time of executing
    this test.

    But I keep getting a RoutingError from Rspec even though it renders ok
    when I just go to the page. So how would I spec it? Thanks
    Maybe just try to log the result of

    user_path(:id => '1')
    user_path(:id => 1)

    in your controller, to see what it gives there?

    In the controller under test I added:

    Rails.logger.debug order_path(:id => 'adsfadf1')

    and this yields in the log:

    /orders/adsfadf1

    Do the standard request tests that are built by rspec-rails
    in the spec/requests/ directory upon `rails g scaffold` function
    correctly?

    HTH,

    Peter

    --
    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.
  • Edward michaels at Feb 7, 2012 at 2:08 pm
    Thanks, you don't declare the restful routes in your controller
    though, right? The error that I'm getting specifies that there is no
    'show' action like this:

    ActionController::RoutingError:
    No route matches {:controller=>"users", :action=>"users/1"}

    So it's looking for a 'users/1' action but of course it's not going to
    find it in the controller.
    On Feb 6, 5:02 am, Peter Vandenabeele wrote:
    On Mon, Feb 6, 2012 at 12:16 AM, edward michaels wrote:
    Hi all,
    I'm trying to test that my users show page renders.  The resource has
    the route /users/:id
    How would I code that for an Rspec test?  So far I've tried these four
    ways:
    it "should have a users show path" do
    get user_path(:action => 'show')
    end
    it "should have a users show path" do
    get user_show_path
    end
    it "should have a users show path" do
    get user_path(:id => '1')
    end
    This variant worked on my side:

    ../spec/requests$ vim orders_spec.rb
    describe "Orders" do
    ...
    describe "GET /order/id" do
    it "routes to a show order" do
    get order_path(:id => "abc123")
    response.status.should be(200)
    end
    end

    Passes when that order is in the test db and fails with
    ActiveRecord::RecordNotFound when I change
    the id to a non-present value, so that seems correct.
    I have the record in the test db at the time of executing
    this test.

    But I keep getting a RoutingError from Rspec even though it renders ok
    when I just go to the page.  So how would I spec it?  Thanks
    Maybe just try to log the result of

    user_path(:id => '1')
    user_path(:id => 1)

    in your controller, to see what it gives there?

    In the controller under test I added:

    Rails.logger.debug order_path(:id => 'adsfadf1')

    and this yields in the log:

    /orders/adsfadf1

    Do the standard request tests that are built by rspec-rails
    in the spec/requests/ directory upon `rails g scaffold` function
    correctly?

    HTH,

    Peter
    --
    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.
  • Peter Vandenabeele at Feb 7, 2012 at 8:35 pm

    On Tue, Feb 7, 2012 at 3:07 PM, edward michaels wrote:

    Thanks, you don't declare the restful routes in your controller
    though, right?

    In the case I showed, I _do_ declare the default RESTful
    routes in the config/routes.rb (they are set there by the
    rails generator):

    $ cat config/routes.rb
    ApplicationName::Application.routes.draw do
    ...
    resources :orders
    ...
    end

    The error that I'm getting specifies that there is no
    'show' action like this:

    ActionController::RoutingError:
    No route matches {:controller=>"users", :action=>"users/1"}

    So it's looking for a 'users/1' action but of course it's not going to
    find it in the controller.
    Did you try `rake routes` to inspect the details ?

    $ rake routes | grep order | grep show
    order GET /orders/:id(.:format)
    orders#show

    HTH,

    Peter

    --
    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.
  • Gerbdla at Feb 7, 2012 at 8:38 pm
    use that looks incorrect the restful actions are actions like
    show
    index
    create

    etc etc
    On Feb 7, 6:07 am, edward michaels wrote:
    Thanks, you don't declare the restful routes in your controller
    though, right?  The error that I'm getting specifies that there is no
    'show' action like this:

    ActionController::RoutingError:
    No route matches {:controller=>"users", :action=>"users/1"}

    So it's looking for a 'users/1' action but of course it's not going to
    find it in the controller.

    On Feb 6, 5:02 am, Peter Vandenabeele wrote:






    On Mon, Feb 6, 2012 at 12:16 AM, edward michaels wrote:
    Hi all,
    I'm trying to test that my users show page renders.  The resource has
    the route /users/:id
    How would I code that for an Rspec test?  So far I've tried these four
    ways:
    it "should have a users show path" do
    get user_path(:action => 'show')
    end
    it "should have a users show path" do
    get user_show_path
    end
    it "should have a users show path" do
    get user_path(:id => '1')
    end
    This variant worked on my side:
    ../spec/requests$ vim orders_spec.rb
    describe "Orders" do
    ...
    describe "GET /order/id" do
    it "routes to a show order" do
    get order_path(:id => "abc123")
    response.status.should be(200)
    end
    end
    Passes when that order is in the test db and fails with
    ActiveRecord::RecordNotFound when I change
    the id to a non-present value, so that seems correct.
    I have the record in the test db at the time of executing
    this test.
    But I keep getting a RoutingError from Rspec even though it renders ok
    when I just go to the page.  So how would I spec it?  Thanks
    Maybe just try to log the result of
    user_path(:id => '1')
    user_path(:id => 1)
    in your controller, to see what it gives there?
    In the controller under test I added:
    Rails.logger.debug order_path(:id => 'adsfadf1')
    and this yields in the log:
    /orders/adsfadf1
    Do the standard request tests that are built by rspec-rails
    in the spec/requests/ directory upon `rails g scaffold` function
    correctly?
    HTH,
    Peter
    --
    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
postedFeb 6, '12 at 9:39a
activeFeb 7, '12 at 8:38p
posts5
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase