Ruby 新手在这里试图掌握 rspec、rails、cucumber。
我不确定为什么会返回以下错误:
1) User can be found by username
Failure/Error: user.should_not be_valid
NoMethodError:
undefined method `valid?' for nil:NilClass
# ./spec/models/user_spec.rb:26:in `block (2 levels) in <top (required)>'
从以下模型规范文件中:
require 'spec_helper'
describe User do
let(:user) { User.new(
:username => 'username',
:password => 'password'
)
}
it "should be createable" do
user.should be_valid
end
it "cannot have an empty username" do
user.username = nil
user.should_not be_valid
end
it "cannot have an empty password" do
user.password = nil
user.should_not be_valid
end
it "can be found by username" do
user = User.find_by_username('username')
user.should be_valid
end
it "can be deleted"
end
我确定这很简单,但我无法弄清楚?