Switch to RSpec
This commit is contained in:
22
spec/manifique/agent_spec.rb
Normal file
22
spec/manifique/agent_spec.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe Manifique::Agent do
|
||||
describe "options" do
|
||||
describe "URL validation" do
|
||||
context "with invalid URL" do
|
||||
it "raises an exception" do
|
||||
expect { Manifique::Agent.new }.to raise_error
|
||||
expect { Manifique::Agent.new(url: "htp://example.com") }.to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "with valid URL" do
|
||||
subject { Manifique::Agent.new(url: "https://example.com") }
|
||||
|
||||
it "creates the instance" do
|
||||
expect(subject.class).to eq(Manifique::Agent)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
54
spec/manifique/web_client_spec.rb
Normal file
54
spec/manifique/web_client_spec.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
require "spec_helper"
|
||||
require "manifique/web_client"
|
||||
|
||||
RSpec.describe Manifique::WebClient do
|
||||
before do
|
||||
stub_request(:get, "http://example.com/404").
|
||||
to_return(body: "", status: 404, headers: {})
|
||||
|
||||
stub_request(:get, "http://example.com/500").
|
||||
to_return(body: "", status: 500, headers: {})
|
||||
end
|
||||
|
||||
describe "#do_get_request" do
|
||||
context "unsuccessful requests" do
|
||||
describe "404" do
|
||||
let(:client) { Manifique::WebClient.new }
|
||||
|
||||
it "raises an exception" do
|
||||
expect {
|
||||
client.send(:do_get_request, 'http://example.com/404')
|
||||
}.to raise_error("Could not fetch http://example.com/404 successfully (404)")
|
||||
end
|
||||
end
|
||||
|
||||
describe "500" do
|
||||
let(:client) { Manifique::WebClient.new }
|
||||
|
||||
it "raises an exception" do
|
||||
expect {
|
||||
client.send(:do_get_request, 'http://example.com/500')
|
||||
}.to raise_error("Could not fetch http://example.com/500 successfully (500)")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# describe "HTTP requests" do
|
||||
# let(:connection) do
|
||||
# Faraday.new do |builder|
|
||||
# builder.adapter :test do |stub|
|
||||
# stub.get('/api/v2/cake') { |env| [ 200, {}, env.params.to_json ]}
|
||||
# stub.post('/api/v2/pizza/body') { |env| [ 200, {}, env.body ]}
|
||||
# stub.post('/api/v2/pizza/query') { |env| [ 200, {}, env.params.to_json ]}
|
||||
# stub.delete('/api/v2/gluhwein') { |env| [ 200, {}, 'delete' ]}
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# it "requests via get" do
|
||||
# expect(subject).to receive(:connection).and_return(connection)
|
||||
# expect(subject.get('/cake', {query: 'coffee'}).body).to eql('{"query":"coffee"}')
|
||||
# end
|
||||
# end
|
||||
end
|
||||
8
spec/manifique_spec.rb
Normal file
8
spec/manifique_spec.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
require "spec_helper"
|
||||
|
||||
RSpec.describe Manifique do
|
||||
it "has a version number" do
|
||||
expect(Manifique::VERSION).not_to be nil
|
||||
end
|
||||
|
||||
end
|
||||
18
spec/spec_helper.rb
Normal file
18
spec/spec_helper.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require "bundler/setup"
|
||||
require "manifique"
|
||||
require 'webmock/rspec'
|
||||
|
||||
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'support/*.rb')].each {|f| require f }
|
||||
RSpec.configure do |config|
|
||||
# Enable flags like --only-failures and --next-failure
|
||||
config.example_status_persistence_file_path = ".rspec_status"
|
||||
|
||||
# Disable RSpec exposing methods globally on `Module` and `main`
|
||||
config.disable_monkey_patching!
|
||||
|
||||
config.include ManifiqueFixtures
|
||||
|
||||
config.expect_with :rspec do |c|
|
||||
c.syntax = :expect
|
||||
end
|
||||
end
|
||||
28
spec/support/fixtures.rb
Normal file
28
spec/support/fixtures.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module ManifiqueFixtures
|
||||
|
||||
def mock_connection(urls={})
|
||||
Faraday.new do |builder|
|
||||
builder.response :json, :content_type => /\bjson$/
|
||||
builder.adapter :test do |stub|
|
||||
urls.each do |http_method, requests|
|
||||
requests.each do |url, fixture|
|
||||
stub.send(http_method, url) { |env| [ 200, {'Content-Type' => 'application/json'}, manifique_fixture(fixture) ]}
|
||||
end
|
||||
end
|
||||
yield stub if block_given?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# returns the content of a fixture file (fixtures/file.json)
|
||||
# if no file is found it will just return the provided param...
|
||||
# (assuming we then don't care about real bitgo contents but just check for a response vale)
|
||||
def manifique_fixture(file)
|
||||
path = File.join(File.expand_path(File.dirname(__FILE__)), '../fixtures', "#{file}.json")
|
||||
if File.exists?(path)
|
||||
File.read(path)
|
||||
else
|
||||
file.to_json # returning the provided param - asuming we don't care about real bitgo values and just check for a response
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user