Skip to content

Instantly share code, notes, and snippets.

@GrahamSM
Created May 4, 2016 15:58
Show Gist options
  • Save GrahamSM/52f9dcb1ef93be1328d7327565c93d19 to your computer and use it in GitHub Desktop.
Save GrahamSM/52f9dcb1ef93be1328d7327565c93d19 to your computer and use it in GitHub Desktop.
gem 'rspec'
gem 'pry'
gem 'byebug'
class Customer
attr_reader :name, :budget
def initialize(name, budget)
@name = name
@budget = budget
end
def within_budget?(amount)
!(amount > 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 false if a price is out of 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 if a price 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