2

我有一个非常基本的 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。我错过了什么?

4

1 回答 1

6

块中定义的实例变量在before示例块 ( it, specify) 中可见,但在块中不可见describe。例如:

specify 'URL should work' do
  visit @affiliate.aff_url
end
于 2012-10-31T17:55:58.090 回答