Skip to content

Instantly share code, notes, and snippets.

@ellismarte
Created May 22, 2016 15:02
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 ellismarte/13b9f091a147c41e2679770604284bcb to your computer and use it in GitHub Desktop.
Save ellismarte/13b9f091a147c41e2679770604284bcb to your computer and use it in GitHub Desktop.
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
# 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