我有一个非常基本的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为零。我想念什么?

最佳答案

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

specify 'URL should work' do
  visit @affiliate.aff_url
end

关于ruby-on-rails - RSpec中意外的nil变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13163885/

10-13 04:44