/
model_generator_spec.rb
52 lines (40 loc) · 1.44 KB
/
model_generator_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'spec_helper'
# Generators are not automatically loaded by Rails
require 'generators/rspec/model/model_generator'
describe Rspec::Generators::ModelGenerator, :type => :generator do
# Tell the generator where to put its output (what it thinks of as Rails.root)
destination File.expand_path("../../../../../tmp", __FILE__)
before { prepare_destination }
it 'runs both the model and fixture tasks' do
gen = generator %w(posts)
expect(gen).to receive :create_model_spec
expect(gen).to receive :create_fixture_file
gen.invoke_all
end
describe 'the generated files' do
describe 'with fixtures' do
before do
run_generator %w(posts --fixture)
end
describe 'the spec' do
subject { file('spec/models/posts_spec.rb') }
it { is_expected.to exist }
it { is_expected.to contain(/require 'rails_helper'/) }
it { is_expected.to contain(/^RSpec.describe Posts, :type => :model/) }
end
describe 'the fixtures' do
subject { file('spec/fixtures/posts.yml') }
it { is_expected.to contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html')) }
end
end
describe 'without fixtures' do
before do
run_generator %w(posts)
end
describe 'the fixtures' do
subject { file('spec/fixtures/posts.yml') }
it { is_expected.not_to exist }
end
end
end
end