Last active
December 21, 2017 00:53
-
-
Save jonduarte/dff29d4b7375fb12e91f485c65661f06 to your computer and use it in GitHub Desktop.
How to fabricate hashes and open structures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/fabricators/stuff.rb | |
Fabricator(:one_stuff, from: :open_struct) do | |
name 'Pedro' | |
end | |
Fabricator(:second_stuff, from: :hash) do | |
after_build do |s| | |
s['name'] = 'Jose' | |
end | |
end | |
# spec/models/example_spec.rb | |
require 'spec_helper' | |
require 'fabrication' | |
describe 'A class' do | |
let(:something) { Fabricate.build(:one_stuff) } | |
let(:elsei) { Fabricate.build(:second_stuff) } | |
it 'is true' do | |
expect(something.name).to eq('Pedro') | |
expect(elsei).to eq({ 'name' => 'Jose' }) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment