Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
Use the the method expect instead of should (#36)
Browse files Browse the repository at this point in the history
- Replace all the should statements for expect
- Configure RSpec to use only expect assertions
  • Loading branch information
jmmercadom committed Sep 30, 2013
1 parent 5c2f3a4 commit 5b278e7
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 53 deletions.
14 changes: 7 additions & 7 deletions spec/integration/e2e_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

it 'verifies the contract against a producer' do
contract = Pacto.build_from_file(contract_path, 'http://localhost:8000')
contract.validate.should == []
expect(contract.validate).to be_empty
end
end

Expand All @@ -27,8 +27,8 @@
contract = Pacto.build_from_file(contract_path, 'http://dummyprovider.com')
Pacto.register_contract(contract, 'my_tag')
Pacto.use('my_tag')
response.keys.should == ['message']
response['message'].should be_kind_of(String)
expect(response.keys).to eq ['message']
expect(response['message']).to be_kind_of(String)
end

let :response do
Expand Down Expand Up @@ -56,13 +56,13 @@

raw_response = HTTParty.get('http://dummyprovider.com/hello', headers: {'Accept' => 'application/json' })
login_response = JSON.parse(raw_response.body)
login_response.keys.should == ['message']
login_response['message'].should be_kind_of(String)
expect(login_response.keys).to eq ['message']
expect(login_response['message']).to be_kind_of(String)

devices_response = HTTParty.get('http://dummyprovider.com/strict', headers: {'Accept' => 'application/json' })
devices_response = JSON.parse(devices_response.body)
devices_response['devices'].should have(2).items
devices_response['devices'][0].should == '/dev/42'
expect(devices_response['devices']).to have(2).items
expect(devices_response['devices'][0]).to eq '/dev/42'
# devices_response['devices'][1].should == '/dev/43'
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/templating_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
c.strict_matchers = false
end

response.keys.should == ['message']
response['message'].should eql("<%= req['HEADERS']['X-Message'].reverse %>")
expect(response.keys).to eq ['message']
expect(response['message']).to eq("<%= req['HEADERS']['X-Message'].reverse %>")
end
end

Expand All @@ -44,8 +44,8 @@
c.postprocessor = Pacto::ERBProcessor.new
end

response.keys.should == ['message']
response['message'].should eql(key.reverse)
expect(response.keys).to eq ['message']
expect(response['message']).to eq(key.reverse)
end
end
end
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
require 'pacto/server'
require 'stringio'
require 'should_not/rspec'

RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect
end
end
3 changes: 1 addition & 2 deletions spec/unit/pacto/contract_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ module Pacto
describe '.build_from_file' do
it 'builds a contract given a JSON file path and a host' do
file_pre_processor.stub(:process).and_return(file_content)
described_class.build_from_file(contract_path, host, file_pre_processor).
should be_a_kind_of(Pacto::Contract)
expect(described_class.build_from_file(contract_path, host, file_pre_processor)).to be_a_kind_of(Pacto::Contract)
end

it 'processes files using File Pre Processor module' do
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/pacto/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
describe 'configure' do
let(:contracts_path) { 'path_to_contracts' }
it 'allows preprocessor manual configuration' do
Pacto.configuration.preprocessor.should_not be_nil
expect(Pacto.configuration.preprocessor).to_not be_nil
Pacto.configure do |c|
c.preprocessor = nil
end
Pacto.configuration.preprocessor.should be_nil
expect(Pacto.configuration.preprocessor).to be_nil
end

it 'allows contracts_path manual configuration' do
Pacto.configuration.contracts_path.should be_nil
expect(Pacto.configuration.contracts_path).to be_nil
Pacto.configure do |c|
c.contracts_path = contracts_path
end
Pacto.configuration.contracts_path.should eql(contracts_path)
expect(Pacto.configuration.contracts_path).to eq(contracts_path)
end
end
end
8 changes: 4 additions & 4 deletions spec/unit/pacto/core/contract_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
described_class.register_contract(contract, tag)
described_class.register_contract(contract, tag)
expect(described_class.registered[tag]).to include(contract)
described_class.registered[tag].should have(1).items
expect(described_class.registered[tag]).to have(1).items
end
end

Expand Down Expand Up @@ -72,12 +72,12 @@
it 'stubs a contract with default values' do
contract.should_receive(:stub!)
another_contract.should_receive(:stub!)
described_class.use(tag).should == 2
expect(described_class.use(tag)).to eq 2
end

it 'stubs default contract if unused tag' do
another_contract.should_receive(:stub!)
described_class.use(another_tag).should == 1
expect(described_class.use(another_tag)).to eq 1
end
end

Expand All @@ -93,7 +93,7 @@
it 'unregisters all previously registered contracts' do
described_class.register_contract(contract, tag)
described_class.unregister_all!
described_class.registered.should be_empty
expect(described_class.registered).to be_empty
end
end
end
14 changes: 7 additions & 7 deletions spec/unit/pacto/extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ module Extensions
describe '#subset_of?' do
context 'when the other hash is the same' do
it 'returns true' do
{:a => 'a'}.should be_subset_of({:a => 'a'})
expect({:a => 'a'}).to be_subset_of({:a => 'a'})
end
end

context 'when the other hash is a subset' do
it 'returns true' do
{:a => 'a'}.should be_subset_of({:a => 'a', :b => 'b'})
expect({:a => 'a'}).to be_subset_of({:a => 'a', :b => 'b'})
end
end

context 'when the other hash is not a subset' do
it 'returns false' do
{:a => 'a'}.subset_of?({:a => 'b'}).should be_false
expect({:a => 'a'}.subset_of?({:a => 'b'})).to be_false
end
end
end

describe '#normalize_keys' do
it 'turns keys into downcased strings' do
{:A => 'a'}.normalize_keys.should == {'a' => 'a'}
{:a => 'a'}.normalize_keys.should == {'a' => 'a'}
{'A' => 'a'}.normalize_keys.should == {'a' => 'a'}
{'a' => 'a'}.normalize_keys.should == {'a' => 'a'}
expect({:A => 'a'}.normalize_keys).to eq({'a' => 'a'})
expect({:a => 'a'}.normalize_keys).to eq({'a' => 'a'})
expect({'A' => 'a'}.normalize_keys).to eq({'a' => 'a'})
expect({'a' => 'a'}.normalize_keys).to eq({'a' => 'a'})
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/pacto/hash_merge_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module Pacto
}

it 'does not change contract if values is nil' do
subject.process(response_body_string, nil).should == response_body_string
expect(subject.process(response_body_string, nil)).to eq response_body_string
end

it 'merges response body with values' do
merged_body = {'a' => 'simple hash', 'b' => :key}
subject.process(response_body_hash, {:b => :key}).should == merged_body.to_s
expect(subject.process(response_body_hash, {:b => :key})).to eq merged_body.to_s
end

end
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/pacto/pacto_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ def mock_validation(errors)
it 'displays a success message and return true' do
mock_validation []
success = Pacto.validate_contract 'my_contract.json'
output.should eq 'All contracts successfully meta-validated'
success.should be_true
expect(output).to eq 'All contracts successfully meta-validated'
expect(success).to be_true
end
end

context 'invalid' do
it 'displays one error messages and return false' do
mock_validation ['Error 1']
success = Pacto.validate_contract 'my_contract.json'
output.should match /error/
success.should be_false
expect(output).to match /error/
expect(success).to be_false
end

it 'displays several error messages and return false' do
mock_validation ['Error 1', 'Error 2']
success = Pacto.validate_contract 'my_contract.json'
success.should be_false
expect(success).to be_false
end
end
end
Expand All @@ -53,7 +53,7 @@ def mock_validation(errors)

it 'returns whatever the factory returns' do
Pacto::ContractFactory.stub(:build_from_file => instantiated_contract)
described_class.build_from_file(path, host, file_pre_processor).should == instantiated_contract
expect(described_class.build_from_file(path, host, file_pre_processor)).to eq instantiated_contract
end
end

Expand Down
32 changes: 16 additions & 16 deletions spec/unit/pacto/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ module Pacto
and_return(generated_body)

response = described_class.new(definition).instantiate
response.status.should == definition['status']
response.headers.should == definition['headers']
response.body.should == generated_body
expect(response.status).to eq definition['status']
expect(response.headers).to eq definition['headers']
expect(response.body).to eq generated_body
end
end

Expand All @@ -45,7 +45,7 @@ module Pacto
and_return([])

response = described_class.new(definition)
response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end
end

Expand All @@ -67,14 +67,14 @@ module Pacto
it 'does not return an error when body is a string' do
response = described_class.new(definition)

response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end

it 'returns an error when body is nil' do
response = described_class.new(definition)

fake_response.stub(:body).and_return(nil)
response.validate(fake_response).size.should == 1
expect(response.validate(fake_response).size).to eq 1
end
end

Expand All @@ -84,14 +84,14 @@ module Pacto
it 'does not return an error when body is a string' do
response = described_class.new(definition)

response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end

it 'does not return an error when body is nil' do
response = described_class.new(definition)

fake_response.stub(:body).and_return(nil)
response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end
end

Expand All @@ -106,7 +106,7 @@ module Pacto
it 'does not return an error' do
response = described_class.new(definition)

response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end
end

Expand All @@ -116,7 +116,7 @@ module Pacto
it 'returns an error' do
response = described_class.new(definition)

response.validate(fake_response).size.should == 1
expect(response.validate(fake_response).size).to eq 1
end
end

Expand All @@ -130,7 +130,7 @@ module Pacto
JSON::Validator.should_not_receive(:fully_validate)

response = described_class.new(definition)
response.validate(fake_response).should == ["Invalid status: expected #{definition['status']} but got #{status}"]
expect(response.validate(fake_response)).to eq ["Invalid status: expected #{definition['status']} but got #{status}"]
end
end

Expand All @@ -141,7 +141,7 @@ module Pacto
JSON::Validator.should_not_receive(:fully_validate)

response = described_class.new(definition)
response.validate(fake_response).should == ["Invalid headers: expected #{definition['headers'].inspect} to be a subset of #{headers.inspect}"]
expect(response.validate(fake_response)).to eq ["Invalid headers: expected #{definition['headers'].inspect} to be a subset of #{headers.inspect}"]
end
end

Expand All @@ -152,7 +152,7 @@ module Pacto
JSON::Validator.stub(:fully_validate).and_return([])

response = described_class.new(definition)
response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end
end

Expand All @@ -163,7 +163,7 @@ module Pacto
JSON::Validator.stub(:fully_validate).and_return([])

response = described_class.new(definition)
response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end
end

Expand All @@ -174,7 +174,7 @@ module Pacto
JSON::Validator.stub(:fully_validate).and_return(errors)

response = described_class.new(definition)
response.validate(fake_response).should == errors
expect(response.validate(fake_response)).to eq errors
end
end

Expand All @@ -193,7 +193,7 @@ module Pacto

it 'gives no errors' do
response = described_class.new(definition)
response.validate(fake_response).should == []
expect(response.validate(fake_response)).to be_empty
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/pacto/stubs/built_in_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Stubs
describe '#initialize' do
it 'sets up a callback' do
WebMock.should_receive(:after_request) do | arg, &block |
block.parameters.size.should == 2
expect(block.parameters).to have(2).items
end

described_class.new
Expand Down

0 comments on commit 5b278e7

Please sign in to comment.