Skip to content

Instantly share code, notes, and snippets.

@Leejojo
Created June 29, 2016 23:45
Show Gist options
  • Save Leejojo/69b183b1125a8632655839a8a9f3c997 to your computer and use it in GitHub Desktop.
Save Leejojo/69b183b1125a8632655839a8a9f3c997 to your computer and use it in GitHub Desktop.
Stubbing Review
gem 'rspec'
gem 'pry'
gem 'byebug'
class Customer
#your code goes here
attr_accessor :name, :budget, :price
def initialize(name, budget)
@name = name
@budget = budget
end
def within_budget?(price)
self.price = price
self.price <= self.budget
end
end
require('rspec')
require_relative('./main')
describe Customer do
describe 'should start with a name and a budget' do
before :each do
@customer = Customer.new('John', 1000)
end
it "should have a name" do
expect(@customer.name).to eq('John')
end
it "should have a budget" do
expect(@customer.budget).to eq(1000)
end
end
describe '#within_budget?' do
before :each do
@customer = Customer.new('Sara', 2000)
end
it "should return true is a price is is within the budget" do
allow(@customer).to receive(:budget) {1999}
expect(@customer.budget).to eq(1999)
expect(@customer.within_budget?(1500)).to eq(true)
end
it "should return false is a price is is out of budget" do
allow(@customer).to receive(:budget) { 100 }
expect(@customer.budget).to eq(100)
expect(@customer.within_budget?(1000)).to eq(false)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment