Sha256: 80e7a839ff1b70b446a5e74c7767fa92e978c3d8e70da430ae06d0b4f7810ec1
Contents?: true
Size: 1.67 KB
Versions: 2
Compression:
Stored size: 1.67 KB
Contents
Feature: Contract tests with spies Whenever you spy on method invocations, it creates a contract specifying that some method can be called with a particular set of arguments. It can be automatically verified by Bogus, whether the method was actually called with those arguments. Background: Given a file named "foo.rb" with: """ruby class Library def checkout(book) end end class Student def read(book, library = Library.new) library.checkout(book) # ... end end """ And a spec file named "student_spec.rb" with: """ruby describe Student do fake(:library) it "reads books from library" do student = Student.new student.read("Moby Dick", library) library.should have_received.checkout("Moby Dick") end end """ Scenario: Stubbing methods that exist on real object Then spec file with following content should pass: """ruby describe Library do verify_contract(:library) it "checks out books" do library = Library.new library.checkout("Moby Dick") # ... end end """ Scenario: Verifing that stubbed methods are tested Then spec file with following content should fail: """ruby describe Library do verify_contract(:library) end """ Scenario: Verifying that methods are tested with right arguments Then spec file with following content should fail: """ruby describe Library do verify_contract(:library) it "checks out books" do library = Library.new library.checkout("Moby Dick 2: The ulitmate") # ... end end """
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
bogus-0.1.0 | features/contract_tests/contract_tests_spies.feature |
bogus-0.0.4 | features/contract_tests/contract_tests_spies.feature |