Skip to content

Instantly share code, notes, and snippets.

@mattvanhorn
Created June 16, 2012 14:26
Show Gist options
  • Save mattvanhorn/2941474 to your computer and use it in GitHub Desktop.
Save mattvanhorn/2941474 to your computer and use it in GitHub Desktop.
display_case testing with rspec
# app/models/post.rb
class Post < ActiveRecord::Base
has_many :comments
end
# app/exhibits/post_exhibit.rb
class PostExhibit< DisplayCase::Exhibit
def self.applicable_to?(object)
object_is_any_of?(object, Post)
end
exhibit_query :comments
end
# spec/exhibits/post_exhibit_spec.rb
require 'spec_helper'
require 'ostruct'
describe PostExhibit do
subject { PostExhibit.new(post, context) }
let(:post) { OpenStruct.new(:comments => comments) }
let(:comments) { Object.new }
let(:context) { Object.new }
it 'exhibits its comments' do
exhibited_comments = Object.new
subject.should_receive(:exhibit).with(comments).and_return(exhibited_comments)
subject.comments.should equal(exhibited_comments)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment