diff --git a/her.gemspec b/her.gemspec index 83ec7861..0476834a 100644 --- a/her.gemspec +++ b/her.gemspec @@ -19,7 +19,6 @@ Gem::Specification.new do |s| s.add_development_dependency "rake", "~> 10.0" s.add_development_dependency "rspec", "~> 2.13" - s.add_development_dependency "mocha", "~> 0.13" s.add_runtime_dependency "activemodel", ">= 3.0.0" s.add_runtime_dependency "activesupport", ">= 3.0.0" diff --git a/spec/model/attributes_spec.rb b/spec/model/attributes_spec.rb index 433419fb..46a1c3c4 100644 --- a/spec/model/attributes_spec.rb +++ b/spec/model/attributes_spec.rb @@ -119,7 +119,7 @@ it "delegates eql? to ==" do other = Object.new - user.expects(:==).with(other).returns(true) + user.should_receive(:==).with(other).and_return(true) user.eql?(other).should be_true end diff --git a/spec/model/orm_spec.rb b/spec/model/orm_spec.rb index b3c2e336..63db0361 100644 --- a/spec/model/orm_spec.rb +++ b/spec/model/orm_spec.rb @@ -367,7 +367,7 @@ def to_params it "delegates eql? to ==" do other = Object.new - user.expects(:==).with(other).returns(true) + user.should_receive(:==).with(other).and_return(true) user.eql?(other).should be_true end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cc6a2811..578d831e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,46 +1,21 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) require "rspec" -require "mocha/api" require "her" +# Require everything in `spec/support` +Dir[File.expand_path('../../spec/support/**/*.rb', __FILE__)].map(&method(:require)) + RSpec.configure do |config| - config.mock_with :mocha + config.include Her::Testing::Macros::ModelMacros config.before :each do - @globals = [] + @spawned_models = [] end config.after :each do - @globals.each do |global| - Object.instance_eval { remove_const global } if Object.const_defined?(global) - end - end -end - -class Hash - def to_json; MultiJson.dump(self); end -end - -class Array - def to_json; MultiJson.dump(self); end -end - -def spawn_model(klass, &block) - if klass =~ /::/ - base, submodel = klass.split(/::/).map{ |s| s.to_sym } - Object.const_set(base, Module.new) unless Object.const_defined?(base) - Object.const_get(base).module_eval do - remove_const submodel if constants.include?(submodel) - submodel = const_set(submodel, Class.new) - submodel.send(:include, Her::Model) - submodel.class_eval(&block) if block_given? + @spawned_models.each do |model| + Object.instance_eval { remove_const model } if Object.const_defined?(model) end - @globals << base - else - Object.instance_eval { remove_const klass } if Object.const_defined?(klass) - Object.const_set(klass, Class.new).send(:include, Her::Model) - Object.const_get(klass).class_eval(&block) if block_given? - @globals << klass.to_sym end end diff --git a/spec/support/extensions/array.rb b/spec/support/extensions/array.rb new file mode 100644 index 00000000..e6cffc02 --- /dev/null +++ b/spec/support/extensions/array.rb @@ -0,0 +1,5 @@ +class Array + def to_json + MultiJson.dump(self) + end +end diff --git a/spec/support/extensions/hash.rb b/spec/support/extensions/hash.rb new file mode 100644 index 00000000..dbbf5f6f --- /dev/null +++ b/spec/support/extensions/hash.rb @@ -0,0 +1,5 @@ +class Hash + def to_json + MultiJson.dump(self) + end +end diff --git a/spec/support/macros/model_macros.rb b/spec/support/macros/model_macros.rb new file mode 100644 index 00000000..7ce96865 --- /dev/null +++ b/spec/support/macros/model_macros.rb @@ -0,0 +1,29 @@ +module Her + module Testing + module Macros + module ModelMacros + # Create a class and automatically inject Her::Model into it + def spawn_model(klass, &block) + if klass =~ /::/ + base, submodel = klass.split(/::/).map{ |s| s.to_sym } + Object.const_set(base, Module.new) unless Object.const_defined?(base) + Object.const_get(base).module_eval do + remove_const submodel if constants.include?(submodel) + submodel = const_set(submodel, Class.new) + submodel.send(:include, Her::Model) + submodel.class_eval(&block) if block_given? + end + + @spawned_models << base + else + Object.instance_eval { remove_const klass } if Object.const_defined?(klass) + Object.const_set(klass, Class.new).send(:include, Her::Model) + Object.const_get(klass).class_eval(&block) if block_given? + + @spawned_models << klass.to_sym + end + end + end + end + end +end