File: render_views.feature

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 (114 lines) | stat: -rw-r--r-- 3,357 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Feature: Using `render_views`

  You can tell a controller example group to render views with the
  `render_views` declaration in any individual group, or globally.

  Scenario: Use `render_views` directly in a single group
    Given a file named "spec/controllers/widgets_controller_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe WidgetsController, type: :controller do
        render_views

        describe "GET index" do
          it "has a widgets related heading" do
            get :index
            expect(response.body).to match /<h1>.*widgets/im
          end
        end
      end
      """
    When I run `rspec spec`
    Then the examples should all pass

  Scenario: Use `render_views` on and off in nested groups
    Given a file named "spec/controllers/widgets_controller_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe WidgetsController, type: :controller do
        context "with render_views" do
          render_views

          describe "GET index" do
            it "renders the actual template" do
              get :index
              expect(response.body).to match /<h1>.*widgets/im
            end
          end

          context "with render_views(false) nested in a group with render_views" do
            render_views false

            describe "GET index" do
              it "renders the RSpec generated template" do
                get :index
                expect(response.body).to eq("")
              end
            end
          end
        end

        context "without render_views" do
          describe "GET index" do
            it "renders the RSpec generated template" do
              get :index
              expect(response.body).to eq("")
            end
          end
        end

        context "with render_views again" do
          render_views

          describe "GET index" do
            it "renders the actual template" do
              get :index
              expect(response.body).to match /<h1>.*widgets/im
            end
          end
        end
      end
      """
    When I run `rspec spec --order defined --format documentation`
    Then the output should contain:
      """ruby
      WidgetsController
        with render_views
          GET index
            renders the actual template
          with render_views(false) nested in a group with render_views
            GET index
              renders the RSpec generated template
        without render_views
          GET index
            renders the RSpec generated template
        with render_views again
          GET index
            renders the actual template
      """

  Scenario: Use `render_views` globally
    Given a file named "spec/support/render_views.rb" with:
      """ruby
      RSpec.configure do |config|
        config.render_views
      end
      """
    And a file named "spec/controllers/widgets_controller_spec.rb" with:
      """ruby
      require "rails_helper"
      require "support/render_views"

      RSpec.describe WidgetsController, type: :controller do
        describe "GET index" do
          it "renders the index template" do
            get :index
            expect(response.body).to match /<h1>.*widgets/im
          end
        end
      end
      """
    When I run `rspec spec`
    Then the examples should all pass