我有一个非常基本的RSpec示例无效。这是代码:
require 'spec_helper'
describe "Referral-type functionality" do
describe "Affiliate system" do
before { @affiliate = Affiliate.create(account_id: 1) }
subject { @affiliate }
describe "URL should work" do
visit @affiliate.aff_url
end
end
end
但是当我运行它时,rspec会给出NoMethodError,因为@affiliate是nil。我错过了什么?
答案 0 :(得分:6)
before
块中定义的实例变量在示例块(it
,specify
)中可见,但在describe
块中不可见。 E.g:
specify 'URL should work' do
visit @affiliate.aff_url
end