File: route_to_matcher.feature

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 (93 lines) | stat: -rw-r--r-- 2,942 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
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
Feature: `route_to` matcher

  The `route_to` matcher specifies that a request (verb + path) is routable.
  It is most valuable when specifying routes other than standard RESTful
  routes.

  ```ruby
  expect(get("/")).to route_to("welcome#index") # new in 2.6.0
  ```
  or

  ```ruby
  expect(:get => "/").to route_to(:controller => "welcome")
  ```

  Scenario: Passing route spec with shortcut syntax
    Given a file named "spec/routing/widgets_routing_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe "routes for Widgets", type: :routing do
        it "routes /widgets to the widgets controller" do
          expect(get("/widgets")).
            to route_to("widgets#index")
        end
      end
      """

    When I run `rspec spec/routing/widgets_routing_spec.rb`
    Then the examples should all pass

  Scenario: Passing route spec with verbose syntax
    Given a file named "spec/routing/widgets_routing_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe "routes for Widgets", type: :routing do
        it "routes /widgets to the widgets controller" do
          expect(:get => "/widgets").
            to route_to(:controller => "widgets", :action => "index")
        end
      end
      """

    When I run `rspec spec/routing/widgets_routing_spec.rb`
    Then the examples should all pass

  Scenario: Route spec for a route that doesn't exist (fails)
    Given a file named "spec/routing/widgets_routing_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe "routes for Widgets", type: :routing do
        it "routes /widgets/foo to the /foo action" do
          expect(get("/widgets/foo")).to route_to("widgets#foo")
        end
      end
      """

    When I run `rspec spec/routing/widgets_routing_spec.rb`
    Then the output should contain "1 failure"

  Scenario: Route spec for a namespaced route with shortcut specifier
    Given a file named "spec/routing/admin_routing_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe "routes for Widgets", type: :routing do
        it "routes /admin/accounts to the admin/accounts controller" do
          expect(get("/admin/accounts")).
            to route_to("admin/accounts#index")
        end
      end
      """

    When I run `rspec spec/routing/admin_routing_spec.rb`
    Then the examples should all pass

  Scenario: Route spec for a namespaced route with verbose specifier
   Given a file named "spec/routing/admin_routing_spec.rb" with:
     """ruby
     require "rails_helper"

     RSpec.describe "routes for Widgets", type: :routing do
       it "routes /admin/accounts to the admin/accounts controller" do
         expect(get("/admin/accounts")).
           to route_to(:controller => "admin/accounts", :action => "index")
       end
     end
     """

   When I run `rspec spec/routing/admin_routing_spec.rb`
   Then the examples should all pass