【发布时间】:2016-01-28 15:16:10
【问题描述】:
我有一个包含辅助方法的 lib/require/environment_helpers.rb 文件。还有更多方法,但没有封装在模块中。
def development?
Rails.env.development?
end
def test?
Rails.env.test?
end
我正在尝试排除这些方法,但没有任何运气。我试过了:
before :each
allow(Rails.env).to receive(:production?) { false }
end
before :each
allow(Rails).to receive(:production?) { false }
end
before :each
allow(ServiceUnderTest).to receive(:production?) { false }
end
【问题讨论】:
-
检查这个问题/答案stackoverflow.com/questions/21153666/…,尤其是这部分代码
receive(:env).and_return(ActiveSupport::StringInquirer.new("production"))
标签: rspec rspec-rails stub