How to remove duplication from RSpec
- by Asa
context "answer is correct" do
before(:each) do
@answer = stub_model(Answer, :correct => true).as_new_record
assigns[:answer] = @answer
render "answers/summarize"
end
it "should display flashcard context properly" do
response.should contain("Quiz")
end
it "should summarize results" do
response.should contain("is correct")
end
end
context "answer is incorrect" do
before(:each) do
@answer = stub_model(Answer, :correct => false).as_new_record
assigns[:answer] = @answer
render "answers/summarize"
end
it "should display flashcard context properly" do
response.should contain("Quiz")
end
it "should summarize results" do
response.should contain("is incorrect")
end
end
How do I avoid repeating the following block within both of the above contexts?
it "should display flashcard context properly" do
response.should contain("Quiz")
end