File: view_generator_spec.rb

package info (click to toggle)
ruby-rspec-rails 8.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,804 kB
  • sloc: ruby: 10,881; sh: 198; makefile: 6
file content (37 lines) | stat: -rw-r--r-- 1,386 bytes parent folder | download | duplicates (2)
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
# Generators are not automatically loaded by Rails
require 'generators/rspec/view/view_generator'
require 'support/generators'

RSpec.describe Rspec::Generators::ViewGenerator, type: :generator do
  setup_default_destination

  describe 'with default template engine' do
    it 'generates a spec for the supplied action' do
      run_generator %w[posts index]
      file('spec/views/posts/index.html.erb_spec.rb').tap do |f|
        expect(f).to contain(/require 'rails_helper'/)
        expect(f).to contain(/^RSpec.describe "posts\/index", #{type_metatag(:view)}/)
      end
    end

    describe 'with a nested resource' do
      it 'generates a spec for the supplied action' do
        run_generator %w[admin/posts index]
        file('spec/views/admin/posts/index.html.erb_spec.rb').tap do |f|
          expect(f).to contain(/require 'rails_helper'/)
          expect(f).to contain(/^RSpec.describe "admin\/posts\/index", #{type_metatag(:view)}/)
        end
      end
    end
  end

  describe 'with a specified template engine' do
    it 'generates a spec for the supplied action' do
      run_generator %w[posts index --template_engine haml]
      file('spec/views/posts/index.html.haml_spec.rb').tap do |f|
        expect(f).to contain(/require 'rails_helper'/)
        expect(f).to contain(/^RSpec.describe "posts\/index", #{type_metatag(:view)}/)
      end
    end
  end
end