Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Spec
- describe Users do
- include UserSpecHelper
- before(:each) do
- @user = mock(User, valid_user_hash)
- dispatch_to(Users, :index)
- end
- describe "#create in general" do
- before(:each) do
- User.stub!(:new).and_return(@user)
- @user.stub!(:save).and_return(true)
- end
- it "requires username on signup" do
- lambda do # <= line 28
- controller = create_user(:username => "")
- controller.assigns(:user).errors.on(:username).should_not be_nil # <= line 30
- controller.should be_successful
- end.should_not change(User, :count)
- end
- end
- end
- ## Result
- Spec::Mocks::MockExpectationError in 'Users#create in general requires username on signup'
- Mock 'User' received unexpected message :errors with (no args)
- ./spec/controllers/users_spec.rb:30:
- ./spec/controllers/users_spec.rb:28:
- ## UserSpecHelper
- module UserSpecHelper
- def valid_user_hash
- {:username => "Blinchik", :password => "665665", :password_confirmation => "665665"}
- end
- def create_user(options = {})
- dispatch_to(Users, :create, :user => valid_user_hash.merge(options))
- end
- end
Add Comment
Please, Sign In to add comment