2013-12-08 51 views
0

我稍早這些錯誤,我增加了Rspec的故障在示例應用程序

attr_accessible :name, :email, :password, :password_confirmation 

user.rb和它似乎解決在發展我的示例應用程序某些功能問題,一切都進行得很順利。於是我決定把它推到Heroku的和不能正常工作,直到我從我的user.rb刪除

attr_accessible :name, :email, :password, :password_confirmation 

線。現在rspec失敗了。有什麼我失蹤?任何幫助表示讚賞。

' c:\Sites\sample_app>bundle exec rspec spec/ 
including Capybara::DSL in the global scope is not recommended! 
.F.............F......FF..FFF.. 

Failures: 

    1) User pages signup with valid information should create a user 
    Failure/Error: expect { click_button submit }.to change(User, :count).by(1) 

     count should have been changed by 1, but was changed by 0 
    # ./spec/requests/user_pages_spec.rb:46:in `block (4 levels) in <top (requi 
red)>' 

    2) User 
    Failure/Error: it { should be_valid } 
     expected #<User id: nil, name: nil, email: nil, created_at: nil, updated_ 
at: nil, password_digest: nil, password: nil> to be valid, but got errors: Passw 
ord can't be blank, Password is too short (minimum is 6 characters), Name can't 
be blank, Email can't be blank, Email is invalid, Password confirmation can't be 
blank 
    # ./spec/models/user_spec.rb:19:in `block (2 levels) in <top (required)>' 

    3) User when email address is already taken 
    Failure/Error: user_with_same_email.email = @user.email.upcase 
    NoMethodError: 
     undefined method `upcase' for nil:NilClass 
    # ./spec/models/user_spec.rb:79:in `block (3 levels) in <top (required)>' 

    4) User when email format is valid should be valid 
    Failure/Error: @user.should be_valid 
     expected #<User id: nil, name: nil, email: "[email protected]", created_at: ni 
l, updated_at: nil, password_digest: nil, password: nil> to be valid, but got er 
rors: Password can't be blank, Password is too short (minimum is 6 characters), 
Name can't be blank, Password confirmation can't be blank 
    # ./spec/models/user_spec.rb:71:in `block (4 levels) in <top (required)>' 
    # ./spec/models/user_spec.rb:69:in `each' 
    # ./spec/models/user_spec.rb:69:in `block (3 levels) in <top (required)>' 

    5) User return value of authenticate method with valid password 
    Failure/Error: it { should == found_user.authenticate(@user.password) } 
    NoMethodError: 
     undefined method `authenticate' for nil:NilClass 
    # ./spec/models/user_spec.rb:43:in `block (4 levels) in <top (required)>' 

    6) User return value of authenticate method with invalid password 
    Failure/Error: let(:user_for_invalid_password) { found_user.authenticate("i 
nvalid") } 
    NoMethodError: 
     undefined method `authenticate' for nil:NilClass 
    # ./spec/models/user_spec.rb:47:in `block (4 levels) in <top (required)>' 
    # ./spec/models/user_spec.rb:49:in `block (4 levels) in <top (required)>' 

    7) User return value of authenticate method with invalid password 
    Failure/Error: let(:user_for_invalid_password) { found_user.authenticate("i 
nvalid") } 
    NoMethodError: 
     undefined method `authenticate' for nil:NilClass 
    # ./spec/models/user_spec.rb:47:in `block (4 levels) in <top (required)>' 
    # ./spec/models/user_spec.rb:50:in `block (4 levels) in <top (required)>' 

Finished in 0.37081 seconds 
31 examples, 7 failures 

Failed examples: 

rspec ./spec/requests/user_pages_spec.rb:45 # User pages signup with valid infor 
mation should create a user 
rspec ./spec/models/user_spec.rb:19 # User 
rspec ./spec/models/user_spec.rb:83 # User when email address is already taken 
rspec ./spec/models/user_spec.rb:67 # User when email format is valid should be 
valid 
rspec ./spec/models/user_spec.rb:43 # User return value of authenticate method w 
ith valid password 
rspec ./spec/models/user_spec.rb:49 # User return value of authenticate method w 
ith invalid password 
rspec ./spec/models/user_spec.rb:50 # User return value of authenticate method w 
ith invalid password' 
+0

顯示在[引擎收錄](http://pastebin.com/) –

+0

http://pastebin.com/jZnPPU2H你'spec'和過去的代碼 - 這是'user_spec.rb'的代碼 – colorcutclarity

回答

0

你有你的spec

2) User Failure/Error: it { should be_valid } 

型號無效的許多錯誤,因爲不救

3) User when email address is already taken 

此錯誤是因爲模型不保存
瞭解valid

valid?(context = nil)
運行所有指定的驗證和是否添加否則爲false沒有錯誤返回true。

my_person = Person.new(params[:person]) 
my_person.valid? 
# => false 

my_person = Person.create(params[:person]) 
my_person.valid? 
# => true 

my_person.errors.add('login', 'can not be empty') if my_person.login == '' 
my_person.valid? 
# => false 

和這麼多隻是讀取錯誤

+0

「這個錯誤,因爲模型沒有保存」這是什麼意思?我對此很陌生,所以你可以詳細說明一下嗎?當我在'user.rb'中使用'attr_accessible:name,:email,:password,:password_confirmation'時,一切都會通過?那條線覆蓋了我所有的rspec或其他東西嗎? – colorcutclarity