Rspec example

describe “An instance of”,‘Cart’ do

before :each do
@cart = Cart.new
end

it “should be properly initialized” do
expect(@cart).to be_a(Cart)
end

context “when new” do
it “contains no items” do
expect(@cart).to be_empty
end
it “has a value of 0” do
expect(@cart.total_value).to be(0)
end
end

context “when a new item is added” do
before do
@cart.items[‘new item’] = “Jonny”
end
it “should no longer be empty” do
expect(@cart.items).not_to be_empty
end
end

 
0
Kudos
 
0
Kudos

Now read this

Test Driven Development in Ruby tuts+ course - Stubs and Mocks notes

Stubbing - A technique used in TDD/BDD allowing you to simulate using third party dependencies for your own code. # Example, retrieving data from a database, you pass a “splat” = dummy data to a stub. We have no control over what our... Continue →