當我運行bundle exec rspec spec /時,我得到21個例子和3個故障。這些故障是:Hartl教程第7章中出現故障的問題
失敗:
1)用戶has_password?如果密碼匹配 故障/錯誤的方法應該是真實的:?@ user.has_password(@ ATTR [:密碼])。應該be_true NoMethodError: 未定義的方法在'has_password?' for nil:NilClass # ./spec/models/user_spec.rb:47:in
塊(3級)
2)用戶has_password?方法應該是假的,如果密碼不匹配 故障/錯誤:@ user.has_password(「無效」)應be_false NoMethodError:在「
3)用戶 未定義的方法has_password?' for nil:NilClass # ./spec/models/user_spec.rb:51:in
塊(3級)密碼驗證應該接受有效的電子郵件地址 故障/錯誤:它「應該拒絕無效的電子郵件地址」做 NoMethodError: 未定義的方法it' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_3:0x00000102eb38b0> # ./spec/models/user_spec.rb:97:in
塊(3級)的「
我會後我的user_spec.rb文件BC我認爲它幾乎是正確的,但不完全。注意到註釋結束,我曾經玩過這些遊戲,但認爲它們是錯誤的,因此將它們評論出來。
require 'spec_helper'
describe User do
before(:each) do
@attr = {
:name => "Example User",
:email => "[email protected]",
:password => "foobar",
:password_confirmation => "foobar" }
end
it "should create a new instance given valid attributes" do
User.create!(@attr)
end
describe "password encryption" do
before(:each) do
@user = User.create!(@attr)
end
it "should have an encrypted password attribute" do
@user.should respond_to(:encrypted_password)
end
it "should set the encrypted password" do
@user.encrypted_password.should_not be_blank
end
end
describe "has_password? method" do
it "should be true if the passwords match" do
@user.has_password?(@attr[:password]).should be_true
end
it "should be false if the passwords don't match" do
@user.has_password?("invalid").should be_false
end
end
describe "password validations" do
it "should require a password" do
User.new(@attr.merge(:password => "", :password_confirmation => "")).
should_not be_valid
end
it "should require a matching password confirmation" do
User.new(@attr.merge(:password_confirmation => "invalid")).
should_not be_valid
end
it "should reject short passwords" do
short = "a" * 5
hash = @attr.merge(:password => short, :password_confirmation => short)
User.new(hash).should_not be_valid
end
it "should reject long passwords" do
short = "a" * 5
hash = @attr.merge(:password => short, :password_confirmation => short)
User.new(hash).should_not be_valid
end
it "should require a name" do
no_name_user = User.new(@attr.merge(:name => ""))
no_name_user.should_not be_valid
end
it "should require an email address" do
no_email_user = User.new(@attr.merge(:email => ""))
no_email_user.should_not be_valid
end
it "should accept valid email addresses" do
addresses = %w[[email protected] [email protected] [email protected]]
addresses.each do |address|
valid_email_user = User.new(@attr.merge(:email => address))
valid_email_user.should be_valid
end
#end
it "should reject invalid email addresses" do
addresses = %w[[email protected],com user_at_foo.org [email protected]]
addresses.each do |address|
invalid_email_user = User.new(@attr.merge(:email => address))
invalid_email_user.should_not be_valid
end
#end
it "should reject duplicate email addresses" do
# Put a user with given email address into the database.
User.create!(@attr)
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
it "should reject email addresses identical up to case" do
upcased_email = @attr[:email].upcase
User.create!(@attr.merge(:email => upcased_email))
user_with_duplicate_email = User.new(@attr)
user_with_duplicate_email.should_not be_valid
end
it "should reject names that are too long" do
long_name = "a" * 51
long_name_user = User.new(@attr.merge(:name => long_name))
long_name_user.should_not be_valid
end
end
end
end
end
我的user.rb文件很好,我認爲。
因此,3次失敗的事情是我的問題的一個方面,但真正讓我擔心的事情是下面的命令:
束的exec rspec的規格/型號/ user_spec.rb -e「?has_password \法」
結果在終端是這樣的:
否例子匹配{:full_description => /( - 混合物:?has_password \\?\方法)/}。
成品在0.00003秒 0實施例中,0失敗
根據Hartl的我應該有2個實施例中,和0故障。想法?任何輸入讚賞:)你的user_spec.rb文件中的