File: model_generator_spec.rb

package info (click to toggle)
ruby-rspec-rails 7.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,796 kB
  • sloc: ruby: 11,068; sh: 198; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 894 bytes parent folder | download
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
# Generators are not automatically loaded by Rails
require 'generators/rspec/model/model_generator'
require 'support/generators'

RSpec.describe Rspec::Generators::ModelGenerator, type: :generator do
  setup_default_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

  it_behaves_like 'a model generator with fixtures', 'admin/posts', 'Admin::Posts'
  it_behaves_like 'a model generator with fixtures', 'posts', 'Posts'

  describe 'the generated files' do
    describe 'without fixtures' do
      before do
        run_generator %w[posts]
      end

      describe 'the fixtures' do
        it "will skip the file" do
          expect(File.exist?(file('spec/fixtures/posts.yml'))).to be false
        end
      end
    end
  end
end