Created
June 29, 2016 23:53
-
-
Save shinobcrc/b139b5960a61278b8d869179988b13e1 to your computer and use it in GitHub Desktop.
Stub Review
This file contains 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
gem 'rspec' | |
gem 'pry' | |
gem 'byebug' |
This file contains 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
class Customer | |
attr_reader :name, :budget | |
def initialize(name, budget) | |
@name = name | |
@budget = budget | |
end | |
def within_budget?(price) | |
price < budget | |
end | |
end |
This file contains 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') | |
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