[英]Rails + Rspec: How to test for environment specific actions? e.g. “… unless Rails.env.production?”
I'm writing a wrapper for a payment processor: 我正在为支付处理器编写一个包装器:
class PaySimpleWrapper
attr_reader :transaction
def initialize(args={})
@transaction.usesandbox = true unless Rails.env.production?
....
How would I test that the usessandbox attribute gets set only in non-production environments? 我如何测试usessandbox属性是否仅在非生产环境中设置?
describe PaySimpleWrapper do
let(:wrapper) { PaySimpleWrapper.new }
describe "when in production" do
before { Rails.stub_chain(:env, :production?) { true } }
it "uses the live system" do
expect(wrapper.transaction.usesandbox).to be_false
end
end
describe "when not in production" do
before { Rails.stub_chain(:env, :production?) { false } }
it "uses the sandbox" do
expect(wrapper.transaction.usesandbox).to be_true
end
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.