Created
March 28, 2014 15:30
-
-
Save markfeedly/9835469 to your computer and use it in GitHub Desktop.
Intro to testing using RSpec for 1-UP workshop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/autorun' | |
class WareHouse | |
attr_reader :quantity | |
def initialize | |
@quantity = 0 | |
end | |
end | |
# RSpec | |
describe "Warehouse inventory" do | |
subject {WareHouse.new} | |
it "should start empty" do | |
expect(subject.quantity).to eq(0) | |
end | |
it "should have a quantity of 1 after adding an item" do | |
subject.add_item | |
expect(subject.quantity).to eq(1) | |
end | |
end | |
=begin | |
a worked example to read through or follow along trying it out | |
http://code.tutsplus.com/tutorials/ruby-for-newbies-testing-with-rspec--net-21297 | |
some common matchers for you to play with | |
expect(subject).to be_true | |
expect(subject).to be_false | |
expect([]).to be_empty | |
expect({:foo => :bar}).to include(:foo => :bar) | |
primes = [1,2,3,5,7] | |
expect(primes).not_to include(4) | |
expect("Some string").to eq("Some string") | |
expect("Some string").not_to match(/foobar/) | |
# Message expectations. The expectation needs to be set up *before* the message is received | |
object = Object.new | |
expect(object).to receive(:do_stuff) | |
object.do_stuff | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://en.wikipedia.org/wiki/Behavior-driven_development
http://chrismdp.com/2013/01/bdd-is-not-cucumber/
http://goodrequirements.com/bdd/
http://guide.agilealliance.org/guide/bdd.html
http://blog.pluralsight.com/tdd-vs-bdd
http://dannorth.net/introducing-bdd/
http://zsoltfabok.com/blog/2011/12/bdd-demonstration/
http://pixelhandler.com/posts/bowling-game-kata-using-mocha-bdd-test-framework-and-yeoman
https://www.relishapp.com/ninjaneering/bdd-kata-conways-life/docs/static-generations