Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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])
Add Comment
Please, Sign In to add comment