我一直收到当使用RSpec的共享示例时,为什么我的本地变量未定义?
friend_or_open_profile_view_spec.rb:14:in 'block in <top (required)>': undefined local variable or method 'another_user' for #<Class:0x007f9d95f16668> (NameError)
。
我能够通过spec的其他地方使用another_user变量就好了。我错过了什么?
另外,有没有更好的方法来做到这一点?配置文件(取决于用户的状态)将显示不同的组件。我最终希望将所有这些组件移动到可根据上下文调用的共享示例中。
require 'spec_helper'
describe "viewing a friend's or an open profile" do
let(:user) { Factory(:user) }
let(:another_user) { Factory(:user) }
before do
sign_in user
User.stub!(:find).and_return(another_user)
end
context "when a profile is marked private" do
it_behaves_like "a restricted profile", another_user
end
你能证明你的共享的例子吗?如果你写'it_behaves_like“受限制的配置文件”,Factory(:user)'? – nathanvda