File: verify_fixture_warning_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 (64 lines) | stat: -rw-r--r-- 1,508 bytes parent folder | download | duplicates (5)
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
require 'rails_helper'

RSpec.describe "Fixture warnings" do
  def generate_fixture_example_group(hook_type)
    RSpec.describe do
      include RSpec::Rails::RailsExampleGroup
      fixtures :things

      before(hook_type) do
        things :a
      end

      it "" do

      end
    end
  end

  it "Warns when a fixture call is made in a before :context call" do
    expect(RSpec).to receive(:warn_with).with(match(/Calling fixture method in before :context/))

    generate_fixture_example_group(:context).run
  end

  it "Does not warn when a fixture call is made in a before :each call" do
    expect(RSpec).not_to receive(:warn_with)

    generate_fixture_example_group(:each).run
  end

end

RSpec.describe "Global fixture warnings" do
  def generate_fixture_example_group(hook_type)
    RSpec.describe do
      include RSpec::Rails::RailsExampleGroup

      before(hook_type) do
        things :a
      end

      it "" do

      end
    end
  end
  around do |ex|
    RSpec.configuration.global_fixtures = [:things]
    ex.call
    RSpec.configuration.global_fixtures = []
  end

  it "warns when a global fixture call is made in a before :context call" do
    expect(RSpec).to receive(:warn_with).with(match(/Calling fixture method in before :context/))

    generate_fixture_example_group(:context).run
  end

  it "does not warn when a global fixture call is made in a before :each call" do
    expect(RSpec).not_to receive(:warn_with)

    generate_fixture_example_group(:each).run
  end
end