Skip to content

Instantly share code, notes, and snippets.

@iain
Created October 19, 2009 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iain/213636 to your computer and use it in GitHub Desktop.
Save iain/213636 to your computer and use it in GitHub Desktop.
Weird RSpec issue
1)
'User should get all active users' FAILED
expected any? to return false, got true
./spec/models/user_spec.rb:26:
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# active :boolean
# created_at :datetime
# updated_at :datetime
#
class User < ActiveRecord::Base
named_scope :active, :conditions => { :active => true }
end
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
Factory.define :active_user, :class => "User" do |f|
f.active true
end
Factory.define :inactive_user, :class => "User" do |f|
f.active false
end
describe User do
it "should get all active users" do
active = Factory(:active_user)
inactive = Factory(:inactive_user)
subject = User.active
subject.should be_all(&:active)
inverse = User.all - subject
inverse.none?(&:active).should be_true
inverse.any?(&:active).should be_false
# inverse.should be_none(&:active)
inverse.should_not be_any(&:active)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment