Skip to content

Instantly share code, notes, and snippets.

@yfeldblum
Created September 19, 2011 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yfeldblum/1227697 to your computer and use it in GitHub Desktop.
Save yfeldblum/1227697 to your computer and use it in GitHub Desktop.
Notes:
mongoid: https://github.com/mongoid/mongoid/commit/15ac280c37ca1f5bcdd517a368bb0735d2806321 (master)
$ bundle exec rspec spec
.FFF
Failures:
1) Widget assigning a not-very-big integer
Failure/Error: it { should be_valid }
expected valid? to return true, got false
# ./spec/models/widget_spec.rb:25:in `block (3 levels) in <top (required)>'
2) Widget assigning a not-very-big integer the errors object should not demand that not_very_big_integer be an integer
Failure/Error: subject.errors[:not_very_big_integer].should_not include "must be an integer"
expected ["must be an integer"] not to include "must be an integer"
Diff:
@@ -1,2 +1,2 @@
-must be an integer
+["must be an integer"]
# ./spec/models/widget_spec.rb:31:in `block (4 levels) in <top (required)>'
3) Widget assigning a not-very-big integer the errors object errors
Failure/Error: its(:errors){ should_not include :not_very_big_integer }
expected #<ActiveModel::Errors:0x00000001be1da0 @base=#<Widget _id: 4e77b68fb2bc071301000004, _type: nil, not_very_big_integer: 1048576.0>, @messages={:not_very_big_integer=>["must be an integer"]}> not to include :not_very_big_integer
Diff:
@@ -1,2 +1,5 @@
-:not_very_big_integer
+#<ActiveModel::Errors:0x00000001be1da0
+ @base=
+ #<Widget _id: 4e77b68fb2bc071301000004, _type: nil, not_very_big_integer: 1048576.0>,
+ @messages={:not_very_big_integer=>["must be an integer"]}>
# ./spec/models/widget_spec.rb:29:in `block (4 levels) in <top (required)>'
Finished in 0.04039 seconds
4 examples, 3 failures
Failed examples:
rspec ./spec/models/widget_spec.rb:25 # Widget assigning a not-very-big integer
rspec ./spec/models/widget_spec.rb:30 # Widget assigning a not-very-big integer the errors object should not demand that not_very_big_integer be an integer
rspec ./spec/models/widget_spec.rb:29 # Widget assigning a not-very-big integer the errors object errors
require "spec_helper"
class Widget
include Mongoid::Document
field :not_very_big_integer,
:type => Integer
validates :not_very_big_integer,
:numericality => {
:only_integer => true,
:allow_nil => true
}
end
describe Widget do
subject { Widget.new }
it { should be_valid } # just to double-check
context "assigning a not-very-big integer" do
let(:not_very_big_integer) { 1048576}
before { subject.not_very_big_integer = not_very_big_integer }
it { should be_valid } # fails
context "the errors object" do
before { subject.valid? }
its(:errors) { should_not include :not_very_big_integer } # fails
it "should not demand that not_very_big_integer be an integer" do
subject.errors[:not_very_big_integer].should_not include "must be an integer" # fails
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment