【发布时间】:2016-09-19 21:29:32
【问题描述】:
这是我的第一个 rspec 测试
我正在使用 Hurtl 的教程,并认为它已经过时了。
我想更改这一行,因为its 不再是 rspec 的一部分:
its(:user) { should == user }
我尝试过这样做:
expect(subject.user).to eq(user)
但是报错
RuntimeError: #let 或 #subject 调用时没有块
如果您需要,这是我的完整 rspec 测试:
require 'spec_helper'
require "rails_helper"
describe Question do
let(:user) { FactoryGirl.create(:user) }
before { @question = user.questions.build(content: "Lorem ipsum") }
subject { @question }
it { should respond_to(:body) }
it { should respond_to(:title) }
it { should respond_to(:user_id) }
it { should respond_to(:user) }
expect(subject.user).to eq(user)
its(:user) { should == user }
it { should be_valid }
describe "accessible attributes" do
it "should not allow access to user_id" do
expect do
Question.new(user_id: user.id)
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
end
end
describe "when user_id is not present" do
before { @question.user_id = nil }
it { should_not be_valid }
end
end
【问题讨论】:
标签: ruby-on-rails rspec