以前工作的基本数据库方法(如“保存”)不再有效,我找不到解决原因的现有问题。Rspec - 无法识别保存功能
运行bundle exec rails spec /抛出对nil的未定义保存:许多位置的Nilclass错误。
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:242:在“module_eval ' c:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:242:'子类' c: /RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.13.1/lib/rspec/core/example_group.rb:228:in'describe ...依此类推...
难道由于宝石版本不匹配?
我使用postgresql的测试和开发数据库是最新的并完全迁移。
我确信有
config.include Capybara::DSL
在我spec_helper.rb文件。
user_spec.rb
.
.
.
describe "with mixed case" do
let(:mixed_case_email) { "[email protected]" }
before { @user.email = mixed_case_email }
describe "should be saved as all lower-case" do
@user.save
expect(@user.email).to eq mixed_case_email.downcase
end
describe "and that's already taken" do
before { user_with_same_email = @user.dup
user_with_same_email.email
user_with_same_email.save }
describe "should be invalid" do
it { should_not be_valid }
end
end
.
.
.
你不能只是把随机代码放在你的Rspec代码的中间。你需要把'user_with_same_email.email; userr_with_same_email.save'在测试的上下文中。 – sevenseacat
我将代码更改为上面的代码。 nil:NilClass的保存未定义方法仍然存在。 – ahnbizcad