File: assertion_delegator_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 (41 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (3)
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
RSpec.describe RSpec::Rails::AssertionDelegator do
  it "provides a module that delegates assertion methods to an isolated class" do
    klass = Class.new {
      include RSpec::Rails::AssertionDelegator.new(RSpec::Rails::Assertions)
    }

    expect(klass.new).to respond_to(:assert)
  end

  it "delegates back to the including instance for methods the assertion module requires" do
    assertions = Module.new {
      def has_thing?(thing)
        things.include?(thing)
      end
    }

    klass = Class.new {
      include RSpec::Rails::AssertionDelegator.new(assertions)

      def things
        [:a]
      end
    }

    expect(klass.new).to have_thing(:a)
    expect(klass.new).not_to have_thing(:b)
  end

  it "does not delegate method_missing" do
    assertions = Module.new {
      def method_missing(method, *args)
      end
    }

    klass = Class.new {
      include RSpec::Rails::AssertionDelegator.new(assertions)
    }

    expect { klass.new.abc123 }.to raise_error(NoMethodError)
  end
end