File: argument_matchers.feature

package info (click to toggle)
ruby-bogus 0.1.5-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 828 kB
  • ctags: 628
  • sloc: ruby: 4,124; makefile: 6; sh: 2
file content (73 lines) | stat: -rw-r--r-- 2,985 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
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
Feature: Argument matchers

  Bogus supports some argument matchers for use, when you don't really care about exact equality of arguments passed in or spied on.

  Background:
    Given a file named "catalog.rb" with:
    """ruby
    class Catalog
      def self.books_by_author_and_title(author, title)
      end
    end
    """

  Scenario: Stubbing methods with any arguments
    Then the following test should pass:
    """ruby
    require_relative 'catalog'

    stub(Catalog).books_by_author_and_title(any_args) { :some_book }

    expect(Catalog.books_by_author_and_title("Arthur Conan Doyle", "Sherlock Holmes")).to eq(:some_book)
    """

  Scenario: Stubbing methods with some wildcard arguments
    Then the following test should pass:
    """ruby
    require_relative 'catalog'

    stub(Catalog).books_by_author_and_title(any_args) { :some_book }
    stub(Catalog).books_by_author_and_title("Mark Twain", anything) { :twains_book }

    expect(Catalog.books_by_author_and_title("Mark Twain", "Tom Sawyer")).to eq(:twains_book)
    expect(Catalog.books_by_author_and_title("Mark Twain", "Huckleberry Finn")).to eq(:twains_book)
    expect(Catalog.books_by_author_and_title("Arthur Conan Doyle", "Sherlock Holmes")).to eq(:some_book)
    """

  Scenario: Stubbing methods with proc arguments matcher
    Then the following test should pass:
    """ruby
    require_relative 'catalog'

    stub(Catalog).books_by_author_and_title(any_args) { :some_book }
    stub(Catalog).books_by_author_and_title(with{|author| author =~ /Twain/ }) { :twains_book }

    expect(Catalog.books_by_author_and_title("Mark Twain", "Tom Sawyer")).to eq(:twains_book)
    expect(Catalog.books_by_author_and_title("M. Twain", "Huckleberry Finn")).to eq(:twains_book)
    expect(Catalog.books_by_author_and_title("Arthur Conan Doyle", "Sherlock Holmes")).to eq(:some_book)
    """

  Scenario: Stubbing methods with proc argument matcher
    Then the following test should pass:
    """ruby
    require_relative 'catalog'

    stub(Catalog).books_by_author_and_title(any_args) { :some_book }
    stub(Catalog).books_by_author_and_title(matches{|author| author =~ /Twain/ }, "Tom Sawyer") { :twains_book }

    expect(Catalog.books_by_author_and_title("Mark Twain", "Tom Sawyer")).to eq(:twains_book)
    expect(Catalog.books_by_author_and_title("M. Twain", "Huckleberry Finn")).to eq(:some_book)
    expect(Catalog.books_by_author_and_title("Arthur Conan Doyle", "Sherlock Holmes")).to eq(:some_book)
    """

  Scenario: Stubbing methods with argument type matcher
    Then the following test should pass:
    """ruby
    require_relative 'catalog'

    stub(Catalog).books_by_author_and_title(any_args) { :some_book }
    stub(Catalog).books_by_author_and_title(any(String), any(String)) { :twains_book }

    expect(Catalog.books_by_author_and_title("Mark Twain", "Tom Sawyer")).to eq(:twains_book)
    expect(Catalog.books_by_author_and_title("M. Twain", :other_book)).to eq(:some_book)
    """