Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should render and should redirect_to are both passing #241

Closed
dnagir opened this issue Oct 14, 2010 · 7 comments
Closed

should render and should redirect_to are both passing #241

dnagir opened this issue Oct 14, 2010 · 7 comments

Comments

@dnagir
Copy link

dnagir commented Oct 14, 2010

With the controller:

class TransactionImportsController < ApplicationController
  def create
    redirect_to transaction_imports_url
  end
end

and the request spec:

describe "TransactionImports" do
  it "should fail" do
    get '/transaction_imports/new'
    post '/transaction_imports' # rendered template is still "new" here!
     response.should redirect_to(transaction_imports_url)
     response.should render_template('new')
   end
end

The spec is passing (it checks logically opposite results).
The reason is that there are 2 requests (get and post). Obviously the result of post preserves the result of the previous get.

I might be missing something, but I suppose it should not be the case in integration test - each response/request should not be in any way related to the others (except the session and cookies).

I also might be doing something wrong of course :)

Using rspec 2.0.0.

@dchelimsky
Copy link
Contributor

Request specs wrap Rails' integration tests, which apparently preserve the full list of what was rendered. I agree each request should probably clear out that list, but that would have to be managed in Rails (the rspec matchers delegate directly to Rails' assertions), so you'd need to report this to the Rails tracker to get it addressed.

That said, this probably hasn't come up before because most folks (myself included) envision request specs as more white-box than black-box, focusing expectations on content rather than low-level details like which template is rendered. Those details are better suited for controller specs, which wrap Rails' functional tests, which only support one request per example.

@dnagir
Copy link
Author

dnagir commented Oct 14, 2010

Thanks. All that makes sense. I can report the issue to rails if somebody would help me to translate the specs above into the rails tests. I am very new to rails unfortunately.

@dchelimsky
Copy link
Contributor

require 'test_helper'

class TransactionImportsTest < ActionController::IntegrationTest
  test "should fail" do
    get '/transaction_imports/new'
    post '/transaction_imports' # rendered template is still "new" here!
    assert_redirected_to(transaction_imports_url)
    assert_template('new')
  end
end

@dnagir
Copy link
Author

dnagir commented Oct 17, 2010

Thanks. Submitted to Rails.

@pixeltrix
Copy link
Contributor

@dnagir
Copy link
Author

dnagir commented Oct 18, 2010

Thanks a lot. That was quick.

@dchelimsky
Copy link
Contributor

Srsly. Well done. Cheers.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants