Created
May 4, 2016 15:58
-
-
Save GrahamSM/52f9dcb1ef93be1328d7327565c93d19 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hidden or 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?(amount) | |
| !(amount > self.budget) | |
| end | |
| end |
This file contains hidden or 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 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