Skip to content

Instantly share code, notes, and snippets.

@c-vetter
Created April 1, 2011 09:25
Show Gist options
  • Save c-vetter/897935 to your computer and use it in GitHub Desktop.
Save c-vetter/897935 to your computer and use it in GitHub Desktop.
Use these files to share blueprints between rspec and cucumber, centralize shams in one file, and store the blueprints in the blueprints directory in rails root. Don't forget to put machinist and ffaker in your Gemfile
require 'machinist/active_record'
require 'sham'
require 'ffaker'
# load all other .rb files in this directory
Dir[File.dirname(__FILE__)+'/*.rb'].each {|f| require f}
Sham.define do
# attribute { value }
end
# Load machinist blueprints
require Rails.root.join('blueprints/_setup.rb')
Before { Sham.reset }
# Load machinist blueprints
require Rails.root.join('blueprints/_setup.rb')
# wrap the mocking/stubbing (=faking) of models for improved spec readability
def fake(model, overrides={} )
# stub_model gives a rails-specific interface, as opposed to double(model)
# model.plan harnesses the neatness of machinist blueprints
stub_model model, model.plan.merge(overrides.symbolize_keys)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment