Switch to RSpec
This commit is contained in:
parent
d166fb110d
commit
180dfc482e
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
||||
.rspec_status
|
||||
|
29
Gemfile.lock
29
Gemfile.lock
@ -15,6 +15,7 @@ GEM
|
||||
coderay (1.1.2)
|
||||
crack (0.4.3)
|
||||
safe_yaml (~> 1.0.0)
|
||||
diff-lcs (1.3)
|
||||
faraday (0.15.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
faraday_middleware (0.12.2)
|
||||
@ -31,9 +32,10 @@ GEM
|
||||
shellany (~> 0.0)
|
||||
thor (>= 0.18.1)
|
||||
guard-compat (1.2.1)
|
||||
guard-minitest (2.4.6)
|
||||
guard-compat (~> 1.2)
|
||||
minitest (>= 3.0)
|
||||
guard-rspec (4.7.3)
|
||||
guard (~> 2.1)
|
||||
guard-compat (~> 1.1)
|
||||
rspec (>= 2.99.0, < 4.0)
|
||||
hashdiff (0.3.7)
|
||||
listen (3.1.5)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
@ -42,7 +44,6 @@ GEM
|
||||
lumberjack (1.0.13)
|
||||
method_source (0.9.0)
|
||||
mini_portile2 (2.3.0)
|
||||
minitest (5.11.3)
|
||||
multipart-post (2.0.0)
|
||||
nenv (0.3.0)
|
||||
nitlink (1.1.0)
|
||||
@ -55,12 +56,23 @@ GEM
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.9.0)
|
||||
public_suffix (3.0.2)
|
||||
purdytest (2.0.0)
|
||||
minitest (~> 5.5)
|
||||
rake (10.5.0)
|
||||
rb-fsevent (0.10.3)
|
||||
rb-inotify (0.9.10)
|
||||
ffi (>= 0.5.0, < 2)
|
||||
rspec (3.7.0)
|
||||
rspec-core (~> 3.7.0)
|
||||
rspec-expectations (~> 3.7.0)
|
||||
rspec-mocks (~> 3.7.0)
|
||||
rspec-core (3.7.1)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-expectations (3.7.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-mocks (3.7.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-support (3.7.1)
|
||||
ruby_dep (1.5.0)
|
||||
safe_yaml (1.0.4)
|
||||
shellany (0.0.1)
|
||||
@ -76,12 +88,11 @@ PLATFORMS
|
||||
DEPENDENCIES
|
||||
bundler (~> 1.16)
|
||||
guard (~> 2.14.2)
|
||||
guard-minitest (~> 2.4.6)
|
||||
guard-rspec (~> 4.7.3)
|
||||
manifique!
|
||||
minitest (~> 5.0)
|
||||
pry (~> 0.11.3)
|
||||
purdytest (~> 2.0)
|
||||
rake (~> 10.0)
|
||||
rspec (~> 3.0)
|
||||
webmock (~> 3.4.2)
|
||||
|
||||
BUNDLED WITH
|
||||
|
@ -1,5 +1,5 @@
|
||||
guard :minitest do
|
||||
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
|
||||
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
|
||||
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
||||
guard :rspec, cmd: 'rspec' do
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^lib/manifique/(.+)\.rb$}) { |m| "spec/manifique/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
end
|
||||
|
10
Rakefile
10
Rakefile
@ -1,10 +1,6 @@
|
||||
require "bundler/gem_tasks"
|
||||
require "rake/testtask"
|
||||
require "rspec/core/rake_task"
|
||||
|
||||
Rake::TestTask.new(:test) do |t|
|
||||
t.libs << "test"
|
||||
t.libs << "lib"
|
||||
t.test_files = FileList["test/**/*_test.rb"]
|
||||
end
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
|
||||
task :default => :test
|
||||
task :default => :spec
|
||||
|
@ -7,7 +7,7 @@ require 'pry'
|
||||
|
||||
module Manifique
|
||||
class WebClient
|
||||
def initialize(options)
|
||||
def initialize(options={})
|
||||
@options = options
|
||||
@url = options[:url]
|
||||
end
|
||||
|
@ -24,12 +24,11 @@ Gem::Specification.new do |spec|
|
||||
|
||||
spec.add_development_dependency "bundler", "~> 1.16"
|
||||
spec.add_development_dependency "rake", "~> 10.0"
|
||||
spec.add_development_dependency "minitest", "~> 5.0"
|
||||
spec.add_development_dependency "purdytest", "~> 2.0"
|
||||
spec.add_development_dependency "rspec", "~> 3.0"
|
||||
spec.add_development_dependency "webmock", "~> 3.4.2"
|
||||
spec.add_development_dependency "pry", "~> 0.11.3"
|
||||
spec.add_development_dependency "guard", "~> 2.14.2"
|
||||
spec.add_development_dependency "guard-minitest", "~> 2.4.6"
|
||||
spec.add_development_dependency "guard-rspec", "~> 4.7.3"
|
||||
|
||||
spec.add_runtime_dependency "faraday", "~> 0.15.2"
|
||||
spec.add_runtime_dependency "faraday_middleware", "~> 0.12.2"
|
||||
|
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
|
@ -1,32 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class ManifiqueTest < Minitest::Test
|
||||
|
||||
def test_that_it_has_a_version_number
|
||||
refute_nil ::Manifique::VERSION
|
||||
end
|
||||
|
||||
def test_init_without_url
|
||||
assert_raises(RuntimeError) { Manifique::Agent.new }
|
||||
end
|
||||
|
||||
def test_init_with_invalid_url
|
||||
assert_raises(RuntimeError) { Manifique::Agent.new(url: "htp:/foo.com") }
|
||||
end
|
||||
|
||||
def test_fetch_metadata_request_404
|
||||
stub_request(:get, "http://example.com/404").
|
||||
to_return(body: "", status: 404, headers: {})
|
||||
|
||||
agent = Manifique::Agent.new(url: 'http://example.com/404')
|
||||
assert_raises(RuntimeError) { agent.fetch_metadata }
|
||||
end
|
||||
|
||||
def test_fetch_metadata_request_500
|
||||
stub_request(:get, "http://example.com/500").
|
||||
to_return(body: "", status: 500, headers: {})
|
||||
|
||||
agent = Manifique::Agent.new(url: 'http://example.com/500')
|
||||
assert_raises(RuntimeError) { agent.fetch_metadata }
|
||||
end
|
||||
end
|
@ -1,6 +0,0 @@
|
||||
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
||||
require "manifique"
|
||||
|
||||
require "minitest/autorun"
|
||||
require "purdytest"
|
||||
require "webmock/minitest"
|
Loading…
x
Reference in New Issue
Block a user