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
module FollowEventTransitionMatcher | |
class FollowEventTransition | |
def initialize(event, options) | |
@event = event | |
@from = options[:from].is_a?(Array) ? options[:from] : [options[:from]] | |
@to = options[:to] | |
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
it "event something should transition from state first to state second" do | |
Model.should follow_event_transition(:something, :from => :first, :to => :second) | |
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
rails movie-planning | |
cd movie-planning | |
script/generate rspec | |
script/generate rspec_model Movie | |
script/generate rspec_model Actor movie_id:integer alive:boolean | |
rake db:migrate | |
rake spec |
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
# app/models/actor.rb | |
class Actor < ActiveRecord::Base | |
belongs_to :movie | |
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
# spec/models/actor_spec.rb | |
require 'spec_helper' | |
describe Actor do | |
describe "#kill" do | |
it "make the actor no longer alive" do | |
a = Actor.new(:alive => true) | |
a.kill | |
a.should_not be_alive | |
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
# app/models/actor.rb | |
class Actor < ActiveRecord::Base | |
def kill | |
self.alive = false | |
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
# spec/models/actor_spec.rb | |
describe Actor do | |
describe "#kill" do | |
before(:each) do | |
@movie = mock_model(Movie).as_null_object | |
@actor = Actor.new(:alive => true, :movie => @movie) | |
end | |
it "makes the actor no longer alive" do | |
@actor.kill |
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
# lib/spec/mocks/methods.rb | |
module Spec | |
module Mocks | |
module Methods | |
def as_null_object | |
__mock_proxy.as_null_object | |
end | |
end | |
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
# lib/spec/mocks/proxy.rb | |
module Spec | |
module Mocks | |
class Proxy | |
@options[:null_object] = true | |
end | |
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
# lib/spec/mocks/mock.rb | |
module Spec | |
module Mocks | |
class Mock | |
def method_missing(sym, *args, &block) | |
__mock_proxy.record_message_received(sym, args, block) | |
begin | |
return self if __mock_proxy.null_object? | |
super(sym, *args, &block) | |
rescue NameError |
OlderNewer