Browse files

make object diff not explode with Rails

  • Loading branch information...
1 parent 61975e0 commit e8e91412cad76e123dbad6c1102e49c720df3783 @davejacobs committed Oct 1, 2012
Showing with 29 additions and 14 deletions.
  1. +0 −11 lib/letters.rb
  2. +1 −0 lib/letters/core_ext.rb
  3. +9 −0 lib/letters/diff.rb
  4. +1 −0 lib/letters/patch/core.rb
  5. +18 −3 spec/letters/patch/rails_spec.rb
View
11 lib/letters.rb
@@ -1,12 +1 @@
require "letters/patch/object"
-require "set"
-
-module Letters
- def self.object_for_diff=(object)
- @@object = object
- end
-
- def self.object_for_diff
- @@object if defined?(@@object)
- end
-end
View
1 lib/letters/core_ext.rb
@@ -1,4 +1,5 @@
require "letters/helpers"
+require "letters/diff"
require "letters/assertion_error"
require "letters/empty_error"
require "letters/nil_error"
View
9 lib/letters/diff.rb
@@ -0,0 +1,9 @@
+module Letters
+ def self.object_for_diff=(object)
+ @@object = object
+ end
+
+ def self.object_for_diff
+ @@object if defined?(@@object)
+ end
+end
View
1 lib/letters/patch/core.rb
@@ -1,4 +1,5 @@
require "letters/patch"
+require "set"
Letters.patch! Numeric
Letters.patch! Symbol
View
21 spec/letters/patch/rails_spec.rb
@@ -1,5 +1,9 @@
class ActiveRecord
- class Base; end
+ class Base
+ def -(other)
+ self
+ end
+ end
end
class ActionController
@@ -11,13 +15,24 @@ class Base; end
end
describe "Rails patches" do
- it "adds methods to each of the specified core classes" do
- require "letters/patch/core"
+ before do
+ require "letters/patch/rails"
+ end
+ it "adds methods to each of the specified core classes" do
[ActiveRecord::Base,
ActionController::Base,
ActionMailer::Base].each do |klass|
klass.new.should respond_to(:a)
end
end
+
+ it "allows d1/d2 pairs" do
+ $stdout.should_receive(:puts)
+
+ lambda do
+ ActiveRecord::Base.new.d1
+ ActiveRecord::Base.new.d2
+ end.should_not raise_error
+ end
end

0 comments on commit e8e9141

Please sign in to comment.