Created
December 10, 2010 01:59
-
-
Save chischaschos/735645 to your computer and use it in GitHub Desktop.
rubyc rspec intro
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 Saludador | |
def initialize(*user) | |
@user = user[0] | |
raise "An user has to be provided" unless @user | |
end | |
def saluda | |
"Hola amigo" | |
end | |
def name | |
@user.name | |
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
$:.unshift(File.dirname(__FILE__)) | |
require 'saludador' | |
describe Saludador do | |
context 'a user object is provided' do | |
subject do | |
user = mock() | |
user.stub!(:name).and_return("juan") | |
Saludador.new(user) | |
end | |
context 'test basic object behavior' do | |
it 'should have a saluda method' do | |
subject.should respond_to("saluda") | |
end | |
it 'should return "Hola amigo" when invoking saluda method' do | |
subject.saluda.should eq("Hola amigo") | |
end | |
end | |
context 'working with user objects' do | |
it 'the initializer should receive an user object' do | |
user = mock() | |
user.stub!(:name).and_return("juan") | |
s = Saludador.new(user) | |
s.name.should eq("juan") | |
end | |
it 'saludador should return Hola amiga plus the name of the user object' | |
end | |
end | |
context 'no user was provided' do | |
it 'should raise an exception' do | |
debugger | |
expect { Saludador.new }.to raise_error | |
expect { Saludador.new }.to raise_error("An user has to be provided") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment