Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UsersController#create:
- def create
- @user = User.new(params[:user])
- if @user.save
- flash[:notice] = "Account registered!"
- redirect_back_or_default account_url
- else
- render :action => :new
- end
- end
- UsersControllerTest:
- context "on POST to :create" do
- setup do
- controller.stubs(:require_no_user).returns(true)
- @the_user = User.generate!
- User.stubs(:new).returns(@the_user)
- post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
- end
- should_assign_to(:user) { @the_user }
- context "with successful creation" do
- setup do
- @the_user.stubs(:save).returns(true)
- end
- should_respond_with :redirect
- should_set_the_flash_to "Account registered!"
- should_redirect_to("the user's account") { account_url }
- end
- context "with failed creation" do
- setup do
- @the_user.stubs(:save).returns(false)
- end
- should_respond_with :success
- should_not_set_the_flash
- should_render_template :new
- end
- end
- Results:
- 1) Failure:
- test: on POST to :create with failed creation should not set the flash. (UsersControllerTest)
- method assert_rejects in assertions.rb at line 56
- method __bind_1246115268_943483 in macros.rb at line 43
- method call in context.rb at line 253
- method test: on POST to :create with failed creation should not set the flash. in context.rb at line 253
- Did not expect the flash to be set, but was {:notice=>"Account registered!"}
- 2) Failure:
- test: on POST to :create with failed creation should render template :new. (UsersControllerTest)
- method __bind_1246115268_974053 in macros.rb at line 193
- method call in context.rb at line 253
- method test: on POST to :create with failed creation should render template :new. in context.rb at line 253
- expecting <"new"> but rendering with <"">
- 3) Failure:
- test: on POST to :create with failed creation should respond with success. (UsersControllerTest)
- method assert_accepts in assertions.rb at line 50
- method __bind_1246115269_76190 in macros.rb at line 133
- method call in context.rb at line 253
- method test: on POST to :create with failed creation should respond with success. in context.rb at line 253
- Expected response to be a 200, but was 302
Add Comment
Please, Sign In to add comment