Skip to content

Instantly share code, notes, and snippets.

@catmando
Last active June 24, 2021 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catmando/49834bfe41afc4a33e0ca91c2ee13017 to your computer and use it in GitHub Desktop.
Save catmando/49834bfe41afc4a33e0ca91c2ee13017 to your computer and use it in GitHub Desktop.
RSPEC Example

Here is a sample spec, there is a bug in the spec (not in the models.)

What is the bug?

describe Order do
  describe "#submit" do

    before do
      @book = Book.new(:title => "RSpec Intro", :price => 20)
      @customer = Customer.new
      @order = Order.new(@book)

      @order.submit
    end

   describe "customer" do
     it "puts the ordered book in customer's order history" do
       expect(@customer.orders).to include(@order)
       expect(@customer.ordered_books).to include(@book)
     end
   end

   describe "order" do
     it "is marked as complete" do
       expect(@order).to be_complete
     end

     it "is not yet shipped" do
       expect(@order).not_to be_shipped
     end
   end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment