File: redirect_to_matcher.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 (40 lines) | stat: -rw-r--r-- 1,470 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
Feature: `redirect_to` matcher

  The `redirect_to` matcher is used to specify that a request redirects to a
  given template or action.  It delegates to
  [`assert_redirected_to`](https://api.rubyonrails.org/classes/ActionDispatch/Assertions/ResponseAssertions.html#method-i-assert_redirected_to).

  It is available in controller specs (spec/controllers) and request
  specs (spec/requests).

  Scenario: Using `redirect_to` with four possible options
    Given a file named "spec/controllers/widgets_controller_spec.rb" with:
      """ruby
      require "rails_helper"

      RSpec.describe WidgetsController , type: :controller do

        describe "#create" do
          subject { post :create, :params => { :widget => { :name => "Foo" } } }

          it "redirects to widget_url(@widget)" do
            expect(subject).to redirect_to(widget_url(assigns(:widget)))
          end

          it "redirects_to :action => :show" do
            expect(subject).to redirect_to :action => :show,
                                           :id => assigns(:widget).id
          end

          it "redirects_to(@widget)" do
            expect(subject).to redirect_to(assigns(:widget))
          end

          it "redirects_to /widgets/:id" do
            expect(subject).to redirect_to("/widgets/#{assigns(:widget).id}")
          end
        end
      end
      """
    When I run `rspec spec/controllers/widgets_controller_spec.rb`
    Then the examples should all pass