File: expand_matcher.rb

package info (click to toggle)
ruby-mustermann19 0.4.3%2Bgit20160621-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 756 kB
  • ctags: 445
  • sloc: ruby: 7,197; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 814 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
RSpec::Matchers.define :expand do |behavior = nil, values = {}|
  values, behavior = behavior, nil if behavior.kind_of?(Hash)
  match do |pattern|
    @string  ||= nil
    begin
      expanded = pattern.expand(behavior, values)
    rescue Exception
      false
    else
      @string ? @string == expanded : !!expanded
    end
  end

  chain :to do |string|
    @string = string
  end

  failure_message do |pattern|
    message =  "expected %p to be expandable with %p" % [pattern, values]
    message << " (%p behavior)" % behavior if behavior
    expanded = pattern.expand(behavior, values)
    message << " and result in %p, but got %p" % [@string, expanded] if @string
    message
  end

  failure_message_when_negated do |pattern|
    "expected %p not to be expandable with %p" % [pattern, values]
  end
end