Skip to content

Instantly share code, notes, and snippets.

@shinobcrc
Created June 29, 2016 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinobcrc/b139b5960a61278b8d869179988b13e1 to your computer and use it in GitHub Desktop.
Save shinobcrc/b139b5960a61278b8d869179988b13e1 to your computer and use it in GitHub Desktop.
Stub Review
gem 'rspec'
gem 'pry'
gem 'byebug'
class Customer
attr_reader :name, :budget
def initialize(name, budget)
@name = name
@budget = budget
end
def within_budget?(price)
price < 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 if a price 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 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