Skip to content

Instantly share code, notes, and snippets.

View lucashungaro's full-sized avatar

Lucas Húngaro lucashungaro

View GitHub Profile
class MovieShelf
attr_accessor :movies
def initialize
@movies = []
end
def lookup(movie)
@movies.detect {|m| m == movie}
end
>> shelf = MovieShelf.new
=> #<MovieShelf:0x36eb88 @movies=[]>
>> m = Movie.new
=> #<Movie:0x33b328>
>> m.title = "Juno"
=> "Juno"
>> m2 = Movie.new
=> #<Movie:0x39968>
>> m2.title = "Transformers"
=> "Transformers"
context "a movie shelf" do
setup { @shelf = MovieShelf.new }
should "let the user store a movie" do
juno = Movie.new("Juno")
shelf.store juno
assert shelf.contains?(juno)
end
end
class Movie
attr_accessor :title
def initialize(title)
self.title = title
end
end
class MovieShelf
def initialize
context "a movie shelf" do
setup { @shelf = MovieShelf.new }
should "show how many movies are stored" do
juno = Movie.new("Juno")
transformers = Movie.new("Transformers")
shelf.store juno
shelf.store transformers
assert_equal 2, shelf.movies_count
end
class MovieShelf
def initialize
@movies = []
end
def store(movie)
@movies << movie
end
def contains?(movie)
it "should be successful" do
Account.expects(:new).with(:current_user => @user, :first_name => "Test", :last_name => "Test").returns(@account)
@account.expects(:login_method=).with(CONFIG::LOGIN::OpenID)
@account.expects(:has_email_and_password=).at_least_once
@account.expects(:has_openid=).twice
do_edit
response.should be_success
response.should render_template("edit")
end
it "has been modified a lot of times" do
Dependency.stubs(:a_method)
NoLongerADependency.stubs(:something).returns(false)
AnotherDependency.stubs(:nonexistent_method).returns(10)
MyClass.new.do_something
end
Mocha::Configuration.prevent(:stubbing_non_existent_method) #prevents stubbing of non-existent methods
Mocha::Configuration.prevent(:stubbing_method_unnecessarily) #prevents stubbing of unused methods
Mocha::Configuration.prevent(:stubbing_non_public_method) #prevents stubbing of non-public methods
Mocha::Configuration.prevent(:stubbing_method_on_non_mock_object) #prevents stubbing on concrete objects