File: general_matchers.feature

package info (click to toggle)
ruby-rspec-mocks 2.14.3-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 868 kB
  • sloc: ruby: 8,131; makefile: 4
file content (85 lines) | stat: -rw-r--r-- 2,686 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
Feature: General matchers

  The `anything`,  `any_args`,  and `no_args` matchers can be used to require the method
  to have arguments (or not) without constraining the details of the argument, such as its
  type,  pattern or value. The `anything` matcher only reflects a single argument, while
  the `any_args` matcher matches any arity.

  Scenario: anything argument matcher
    Given a file named "stub_anything_args_spec.rb" with:
      """ruby
      describe "stubbed anything() args spec" do
        it "works" do
          object = Object.new
          object.stub(:foo).with(anything) do
            "anything"
          end

          object.foo(1).should eq("anything")
          object.foo(:that).should eq("anything")
        end
      end
      """
    When I run `rspec stub_anything_args_spec.rb`
    Then the output should contain "1 example, 0 failures"

  Scenario: any_args argument matcher
    Given a file named "stub_any_args_spec.rb" with:
      """ruby
      describe "stubbed any_args() args spec" do
        it "works" do
          object = Object.new
          object.stub(:foo).with(any_args) do
            "anything"
          end

          object.foo(1).should eq("anything")
          object.foo(:that).should eq("anything")
          object.foo.should eq("anything")
        end
      end
      """
    When I run `rspec stub_any_args_spec.rb`
    Then the output should contain "1 example, 0 failures"

  Scenario: no_args argument matcher
    Given a file named "stub_no_args_spec.rb" with:
      """ruby
      describe "stubbed no_args() args spec" do
        it "works for no args" do
          object = Object.new
          object.stub(:foo).with(no_args) do
            "nothing"
          end
          object.stub(:foo).with(anything) do
            "something"
          end

          object.foo(:that).should eq("something")
          object.foo.should eq("nothing")
        end
      end
      """
    When I run `rspec stub_no_args_spec.rb`
    Then the output should contain "1 example, 0 failures"

  Scenario: no_args argument matcher for expectations
    Given a file named "stub_no_args_expectations_spec.rb" with:
      """ruby
      describe "stubbed no_args() args spec for expectations" do
        it "works for no args" do
          object = Object.new
          object.should_receive(:foo).with(no_args)

          object.foo
        end
        it "fails for args" do
          object = Object.new
          object.should_receive(:foo).with(no_args)

          object.foo(:bar)
        end
      end
      """
    When I run `rspec stub_no_args_expectations_spec.rb`
    Then the output should contain "2 examples, 1 failure"