Functional test for 'create' fails : Expected response to be a redirect to <http://test.host/users/1001> but was a redirect to <http://test.host/users>

68 views
Skip to first unread message

mvcaraiman

unread,
Nov 10, 2010, 4:03:38 AM11/10/10
to shoulda
Hi folks,
I have a problem trying to use shoulda with factory_girl when
creating a functional test for 'create' . I created a simple project,
scaffolded user, added 'shoulda' (current gem version on my system
2.11.3 ) and 'factory_girl' in test_helper.rb. Following are the steps
to reproduce it :
0. rails project
1. scaffold user name:string
2. test_helper.rb
require 'shoulda'
require 'factory_girl'
3. rake db:migrate
4. write functional test for user :

class UsersControllerTest < ActionController::TestCase
Factory.define(:user) do |u|
u.name 'joe'
end

context "should create user" do
context "with valid data" do
setup do
User.any_instance.expects(:save).returns(true).once
User.any_instance.stubs(:id).returns(1001)
post :create, :user => {}
end

should_assign_to :user, :class => User
should_set_the_flash_to "User was successfully created."
should_redirect_to("user page"){user_path(1001)}
end
end
end

5. Running the test with "rake test:functionals" shows failure :
Expected response to be a redirect to <http://test.host/users/1001>
but was a redirect to <http://test.host/users>.

I played also with "should redirect_to", because I saw
"should_redirect_to" is deprecated, but with no luck. Do you have any
ideas ?

Thank you in advance,
Marian Vasile Caraiman.
Reply all
Reply to author
Forward
0 new messages