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
|
require 'simplecov'
require 'webmock'
require 'vcr'
# For some reason rspec wasn't included
require 'rspec'
# We do not need pry to run tests during the build
#require 'pry' if RUBY_VERSION > "1.8.7"
class InceptionFormatter
def format(result)
Coveralls::SimpleCov::Formatter.new.format(result)
end
end
def setup_formatter
SimpleCov.formatter = if ENV['TRAVIS'] || ENV['COVERALLS_REPO_TOKEN']
InceptionFormatter
else
SimpleCov::Formatter::HTMLFormatter
end
# SimpleCov.start 'test_frameworks'
SimpleCov.start do
add_filter do |source_file|
source_file.filename =~ /spec/ && !(source_file.filename =~ /fixture/)
end
end
end
setup_formatter
require 'coveralls'
VCR.configure do |c|
c.cassette_library_dir = 'fixtures/vcr_cassettes'
c.hook_into :webmock
end
RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.include WebMock::API
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.mock_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.after(:suite) do
WebMock.disable!
end
end
def stub_api_post
body = "{\"message\":\"\",\"url\":\"\"}"
stub_request(:post, Coveralls::API::API_BASE+"/jobs").with(
:headers => {
'Accept'=>'*/*; q=0.5, application/xml',
'Accept-Encoding'=>'gzip, deflate',
'Content-Length'=>/.+/,
'Content-Type'=>/.+/,
'User-Agent'=>'Ruby'
}
).to_return(:status => 200, :body => body, :headers => {})
end
def silence
return yield if ENV['silence'] == 'false'
silence_stream(STDOUT) do
yield
end
end
module Kernel
def silence_stream(stream)
old_stream = stream.dup
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
stream.sync = true
yield
ensure
stream.reopen(old_stream)
end
end
|