Skip to content

Instantly share code, notes, and snippets.

@asdavey
Created April 26, 2012 06:50
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 asdavey/2496898 to your computer and use it in GitHub Desktop.
Save asdavey/2496898 to your computer and use it in GitHub Desktop.
SystemStackError with RSpec mocks any_instance and DataMapper validators
source 'http://rubygems.org'
DM_VERSION = "~> 1.2.0"
gem 'dm-core', DM_VERSION
gem 'dm-validations', DM_VERSION
gem 'dm-sqlite-adapter', DM_VERSION
gem 'dm-migrations', DM_VERSION
gem 'rspec'
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.7)
data_objects (0.10.8)
addressable (~> 2.1)
diff-lcs (1.1.3)
dm-core (1.2.0)
addressable (~> 2.2.6)
dm-do-adapter (1.2.0)
data_objects (~> 0.10.6)
dm-core (~> 1.2.0)
dm-migrations (1.2.0)
dm-core (~> 1.2.0)
dm-sqlite-adapter (1.2.0)
dm-do-adapter (~> 1.2.0)
do_sqlite3 (~> 0.10.6)
dm-validations (1.2.0)
dm-core (~> 1.2.0)
do_sqlite3 (0.10.8)
data_objects (= 0.10.8)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
PLATFORMS
ruby
DEPENDENCIES
dm-core (~> 1.2.0)
dm-migrations (~> 1.2.0)
dm-sqlite-adapter (~> 1.2.0)
dm-validations (~> 1.2.0)
rspec
require 'rubygems'
require 'bundler/setup'
require 'dm-core'
require 'dm-validations'
require 'rspec'
require 'dm-migrations'
DataMapper.setup(:default, 'sqlite::memory:')
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
validates_uniqueness_of :title
end
DataMapper.auto_migrate!
describe Post do
it "okay with validators being mocked" do
DataMapper::Validations::UniquenessValidator.any_instance.stub(:valid?).and_return(false)
p = Post.new
p.title = "foobar"
p.should_not be_valid
end
it "should still work after mocks have been removed" do
p = Post.new
p.title = "dog"
p.valid?.should be_true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment