Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] assert_recognizes should work in Integration Tests

#4390

this was still working in beta1
(but broke in beta2... which I didn't get round to try)

anyway

here's the example of my use

class RoutingTest < ActionDispatch::IntegrationTest
  
  test "/projects" do
    assert_recognizes({:controller => "projects", :action => "index"}, "/projects")
    assert_recognizes({:controller => "projects", :action => "show", :id => "23"}, "/projects/23")
  end

end

I tend to do these routing tests as an integration test... as that's kind of what they are.
but since beta2 this gives the following error

Error:
test/projects(RoutingTest):
  NoMethodError: undefined method recognize_path' for nil:NilClass
  /test/integration/routing_test.rb:6:intest/projects'

As you can see this error is kind of obscure,
but comes from the fact that @routes is not set by default in an IntegrationTest

Its possible that this kind of test shouldn't be possible
(I'm kind of testing controller structure, whereas it could be argued that integration tests are supposed to be independent of this type of thing...)

I think either this patch should be applied
or the RoutingAssertions should not be included into IntegrationTest
(seems like a bad idea to have an assertion that will never work)

Anyway,
here is my patch
http://github.com/matthewrudy/rude-rails/commit/67f1f2340977d490a5f...
http://github.com/matthewrudy/rude-rails/tree/integration-tests-sho...

and attached also

Reported by MatthewRudy · April 14th, 2010 @ 05:57 AM

State: committed
Milestone: 3.0.2
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: Low

Activity

  1. MatthewRudy
    MatthewRudy
    • Assigned user set to Santiago Pastorino

    I don't know if this is the right answer...
    but...
    it broke my tests..

    Like I say,
    perhaps the answer is not to include these assertions
    but as it stands the assertions exist
    but will not work
    unless we do the

    setup do
      @routes = :blah
    end
    
    ourselves in the integration test.

    Alternatively
    we could add an exception
    explaining this hack
    to the assertion

    April 15th, 2010 @ 06:18 AM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to invalid

    assert_recognizes doesn't make sense on an IntegrationTest use it in Functional tests

    April 23rd, 2010 @ 12:27 AM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from invalid to open

    Perhaps it's not the best use case but should work. Need more discussion here

    April 23rd, 2010 @ 01:01 AM

  4. MatthewRudy
    MatthewRudy

    I agree it may not make sense,
    but it seems wrong that the method is included,
    but is guaranteed to break.

    I've got another fix in my head
    give me a mo,
    I'll attach another patch.

    April 23rd, 2010 @ 07:03 AM

  5. Santiago Pastorino
    Santiago Pastorino
    • Milestone cleared.

    Matthew Rudy I have a solution but i'll wait i want to apply yours ;)

    April 23rd, 2010 @ 02:16 PM

  6. MatthewRudy
    MatthewRudy

    sorry Santiago

    I am in Taipei,
    didnt have internet to upload my patch.

    I'd like to see you solution,
    but here's mine

    basically I decided that the line in the assertion which assumes "@routes" is set
    can just throw an exception if its not
    and suggest adding the @routes = ...

    attached as a patch
    and on github

    http://github.com/matthewrudy/rude-rails/commit/c333d0bea336f1ecf8a...
    http://github.com/matthewrudy/rude-rails/tree/make-assert-recognise...

    April 24th, 2010 @ 05:20 PM

  7. Santiago Pastorino
    Santiago Pastorino
    • Assigned user changed from Santiago Pastorino to Jeremy Kemper

    MatthewRudy here is the fix, i've made with your name ;) http://github.com/spastorino/rails/commit/ed1aa8e0bd33480cb2d10942d... and here are the tests http://github.com/spastorino/rails/commit/7e5e9338a6e9f85df1506c843...
    Let's wait for Jeremy revision.
    Thank you!.

    April 24th, 2010 @ 11:29 PM

  8. Repository
    Repository
    • State changed from open to committed

    April 24th, 2010 @ 11:45 PM

  9. Repository
  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM