spec/spec_helper.rb in marvel_api-0.2.0 vs spec/spec_helper.rb in marvel_api-0.2.1
- old
+ new
@@ -1,16 +1,67 @@
+require 'simplecov'
+require 'coveralls'
+
+SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
+ SimpleCov::Formatter::HTMLFormatter,
+ Coveralls::SimpleCov::Formatter
+]
+
+SimpleCov.start
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
+
require 'rspec'
+require 'webmock/rspec'
require 'marvel_api'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
-Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
RSpec.configure do |config|
-
+ config.expect_with(:rspec) { |c| c.syntax = :expect }
end
-Marvel.configure do |config|
-
+WebMock.disable_net_connect!(allow: 'coveralls.io')
+
+def marvel_test_client
+ Marvel::Client.new.tap do |client|
+ client.configure do |config|
+ config.api_key = '1234'
+ config.private_key = 'abcd'
+ end
+ end
+end
+
+AUTH = '?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150'
+
+def stub_get(path, options = {})
+ file = options.delete(:returns)
+ code = options.delete(:response_code) || 200
+ etag = options.delete(:etag)
+ headers = Marvel::Connection::HEADERS
+ headers.merge!('If-None-Match' => etag) if etag
+ params = '&' + options.map { |k, v| "#{k}=#{v}" } * '&'
+ endpoint = Marvel::Connection::BASE_API_URL + path + AUTH + params
+ stub_request(:get, endpoint)
+ .with(headers: headers)
+ .to_return(body: fixture(file), status: code)
+end
+
+def fixture_path
+ File.expand_path('../fixtures', __FILE__)
+end
+
+def fixture(file)
+ File.new(fixture_path + '/' + file) rescue nil
+end
+
+module Marvel
+ module Request
+ private
+ def timestamp
+ '1'
+ end
+ end
end
\ No newline at end of file