-
-
Save ellismarte/13b9f091a147c41e2679770604284bcb to your computer and use it in GitHub Desktop.
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 Person | |
attr_accessor :name, :age | |
def initialize(args) | |
@name = args[:name] | |
@age = args[:age] | |
end | |
def scream_greeting | |
greeting = get_greeting | |
return greeting | |
end | |
def get_greeting | |
return "hello world" | |
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 'spec_helper' # this is not necessary since we add this to .rspec | |
require_relative "../lib/Person.rb" | |
# ##### Execution ##### | |
# run with 'rspec --format doc --color Person_spec.rb' | |
# or run with 'rspec --format html --color Person_spec.rb > results.html | |
# followed by open results.html' | |
# ##### General ##### | |
# describe is a method, it is a way to group examples | |
# it is a method, it describes a property | |
# store flags you'd pass into to rspec command in .rspec | |
# add configuration to spec_helper. rb | |
# ##### Tips ##### | |
# Test for expected behavior NOT implementation | |
RSpec.describe 'a person' do | |
it 'has a name' do | |
raise unless Person.new({:name => 'ellis'}).name == 'ellis' | |
end | |
it 'has an age' do | |
raise unless Person.new({:age => 26}).age = 26 | |
end | |
describe '#scream_greeting' do | |
it 'should return hello world' do | |
person = double() | |
person.stub(:get_greeting) | |
expect(Person.new({}).scream_greeting).to eq("hello world") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment