/
spec_helper.rb
103 lines (82 loc) · 2.78 KB
/
spec_helper.rb
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
ENV['RAILS_ENV'] = ENV['ENV'] = 'test'
RSpec.configure do |c|
c.before(:each) { Time.now.utc.tap { | now| Time.stubs(:now).returns(now) } }
end
require 'travis/task'
require 'travis/addons'
require 'travis/support/testing/webmock'
require 'travis/testing'
require 'travis/config'
require 'payloads'
ActionMailer::Base.delivery_method = :test
require 'mocha'
require 'gh'
include Mocha::API
RSpec.configure do |c|
c.mock_with :mocha
c.alias_example_to :fit, :focused => true
c.filter_run :focused => true
c.run_all_when_everything_filtered = true
c.backtrace_exclusion_patterns = []
c.include Travis::Support::Testing::Webmock
c.before :each do
Travis.config.oauth2 ||= {}
Travis.config.oauth2.scope = 'public_repo,user'
GH.reset
end
end
RSpec::Matchers.define :deliver_to do |expected|
match do |email|
actual = (email.to || []).map(&:to_s)
description { "be delivered to #{expected.inspect}" }
failure_message_for_should { "expected #{email.inspect} to deliver to #{expected.inspect}, but it delivered to #{actual.inspect}" }
failure_message_for_should_not { "expected #{email.inspect} not to deliver to #{expected.inspect}, but it did" }
actual.sort == Array(expected).sort
end
end
RSpec::Matchers.define :include_lines do |lines|
match do |text|
lines = lines.split("\n").map { |line| line.strip }
missing = lines.reject { |line| text.include?(line) }
failure_message_for_should do
"expected\n\n#{text}\n\nto include the lines\n\n#{lines.join("\n")}\n\nbut could not find the lines\n\n#{missing.join("\n")}"
end
missing.empty?
end
end
RSpec::Matchers.define :contain_recipients do |expected|
match do |actual|
actual = Array(actual).join(',').split(',')
expected = Array(expected).join(',').split(',')
(actual & expected).size.should == expected.size
end
failure_message_for_should do |actual|
"expected #{actual} to contain #{expected}"
end
failure_message_for_should_not do |actual|
"expected #{actual} to not contain #{expected}"
end
end
RSpec::Matchers.define :have_message do |event, object|
match do |pusher|
description { "have a message #{event.inspect}" }
failure_message_for_should { "expected pusher to receive #{event.inspect} but it did not. Instead it has the following messages: #{pusher.messages.map(&:inspect).join(', ')}" }
failure_message_for_should_not { "expected pusher not to receive #{event.inspect} but it did" }
# TODO need to test for the object/json, too!
message = pusher.messages.detect { |message| message.first == event }
pusher.messages.delete(message)
!!message
end
def find_message
end
end
module Kernel
def capture_stdout
out = StringIO.new
$stdout = out
yield
return out.string
ensure
$stdout = STDOUT
end
end