這是我的第一個rspec測試 我使用的是Hurtl的教程,並認爲它已過時。 我想改變這條線,因爲its
不再rspec的一部分:RuntimeError:#let或#subject不帶塊調用
its(:user) { should == user }
我試着這樣做:
expect(subject.user).to eq(user)
但得到一個錯誤
RuntimeError: #let or #subject called without a block
這是我的全面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