mardi 20 janvier 2015

Changing rspec instance_double return values after each test

I am testing a Ruby class with Rspec. I would like to change an instance double's return values between these two contexts, i.e., I want tallied_data.a_conv, tallied_data.a_nonconv, etc. to return different values for the "when A is winner" context. Is there any way I can do this without having to create a new instance_double and repeat all of the code in lines 3-9? Is there a different way to approach this?



describe ABSplitTest do
describe "#test_winner" do
let(:tallied_data) do
instance_double("ABDataSummary",
a_conv: 50, a_nonconv: 51,
b_conv: 52, b_nonconv: 53,
to_h: { a: { conv: 50, nonconv: 51 }, b: { conv:52, nonconv: 53 } }
)
end
subject(:sample_test) { ABSplitTest.new(tallied_data) }

context "when there is no winner" do
it "returns that there is no clear winner" do
expect(sample_test.test_winner).to \
eq("No winner at 0.05 significance")
end
end

context "when A is winner" do
it "returns that A is winner" do
expect(sample_test.test_winner).to \
eq("No winner at 0.05 significance")
end
end

Aucun commentaire:

Enregistrer un commentaire