Created
May 13, 2010 15:11
-
-
Save rafaelss/399926 to your computer and use it in GitHub Desktop.
This file contains 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/support/matchers/attribute.rb | |
module AttributeMatchers | |
Spec::Matchers.define :have_only_attributes do |attributes| | |
match do |target| | |
actual_attributes = target.attribute_names.map(&:to_sym) | |
diff = ((actual_attributes | attributes) - (actual_attributes & attributes)) | |
diff.length == 0 | |
end | |
end | |
end | |
# spec/spec_helper | |
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file } | |
Spec::Runner.configure do |config| | |
config.include AttributeMatchers | |
end | |
# app/models/user.rb | |
class User < ActiveRecord::Base | |
def self.method_returning_only_one_user | |
first(:select => "first_name, last_name, email") | |
end | |
end | |
# spec/models/user_spec.rb | |
User.method_returning_only_one_user.should have_only_attributes([:first_name, :last_name, :email]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment