我正在为付款处理器编写包装器:
class PaySimpleWrapper
attr_reader :transaction
def initialize(args={})
@transaction.usesandbox = true unless Rails.env.production?
....
我如何测试usessandbox属性是否仅在非生产环境中设置?
答案 0 :(得分:3)
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