How to remove duplication from RSpec

Posted by Asa on Stack Overflow See other posts from Stack Overflow or by Asa
Published on 2010-03-22T20:41:20Z Indexed on 2010/03/23 2:51 UTC
Read the original article Hit count: 334

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about rspec

Related posts about ruby-on-rails