Ruby on rails Rspec-无法识别保存功能
像“save”这样以前有效的基本数据库方法现在已经不起作用了,我也找不到解决原因的现有问题 运行bundle exec rails spec/会对许多位置抛出未定义的save for 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:in'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'description 等等 可能是因为gem版本不匹配吗 我使用postgresql的测试和开发数据库是最新的,并已完全迁移 我一定要Ruby on rails Rspec-无法识别保存功能,ruby-on-rails,rspec,capybara,Ruby On Rails,Rspec,Capybara,像“save”这样以前有效的基本数据库方法现在已经不起作用了,我也找不到解决原因的现有问题 运行bundle exec rails spec/会对许多位置抛出未定义的save for 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:in'module_eval' c:/RailsInstaller/Ru
config.include Capybara::DSL
在我的spec_helper.rb文件中
user_spec.rb
.
.
.
describe "with mixed case" do
let(:mixed_case_email) { "FooBaR@GmAIL.CoM" }
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
.
.
.
“Save”方法在Rspec中运行良好。它还有其他一些问题
describe 'Anything goes here ...' do
before do
@p = Project.create(:name => 'logtasks')
@p.save
end
it { expect(@p.name).to eq 'logtasks' }
end
描述“这里有什么……”做什么
在做之前
@p=Project.create(:name=>logtasks)
@p、 拯救
终止
它{expect(@p.name).to eq'logtasks'}
终止
<代码>
你不能把随机代码放在你的RSPEC代码的中间。您需要将用户\u与\u相同\u email.email;userr_与_same_电子邮件。将
保存在测试上下文中。我将代码更改为上述内容。nil:NilClass的save undefined方法仍然存在。