Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #36 from seomoz/build-on-2.0

Build on 2.0
  • Loading branch information...
commit ebe6310522856508f4e6e27644967ef079d5fac1 2 parents c453426 + b61d247
@myronmarston myronmarston authored
View
3  .travis.yml
@@ -8,7 +8,4 @@ rvm:
- 2.0.0
- jruby-19mode
- rbx-19mode
-matrix:
- allow_failures:
- - rvm: 2.0.0
View
2  Gemfile
@@ -13,7 +13,7 @@ gem 'compass_twitter_bootstrap', :git => 'git://github.com/vwall/compass-twitter
gem 'json', :platform => 'ruby_18'
-gem 'cane', '~> 2.6', :platform => 'ruby_19'
+gem 'cane', '~> 2.6' if RUBY_VERSION.to_f > 1.8
# 1.6 won't install on JRuby or 1.8.7 :(.
gem 'nokogiri', '~> 1.5.10'
View
30 spec/unit/interpol/configuration_spec.rb
@@ -146,7 +146,7 @@ def find_with_status_code(status_code, options)
write_file "#{dir}/e2.yml", endpoint_definition_yml.gsub("project", "task")
config.endpoint_definition_files = Dir["#{dir}/*.yml"]
- expect(config).to have(2).endpoints
+ expect(config.endpoints.size).to eq(2)
expect(config.endpoints.map(&:name)).to match_array %w[ project_list task_list ]
end
@@ -173,7 +173,7 @@ def find_with_status_code(status_code, options)
end
it 'is not prone to being reloaded when the configuration is customized' do
- Endpoint.should_receive(:new).once.and_call_original
+ expect(Endpoint).to receive(:new).once.and_call_original
write_file "#{dir}/e1.yml", endpoint_definition_yml
config.endpoint_definition_files = Dir["#{dir}/*.yml"]
@@ -216,7 +216,7 @@ def assert_expected_endpoint
expect(config.endpoints.size).to eq(1)
endpoint = config.endpoints.first
defs = endpoint.definitions
- expect(defs).to have_at_least(1).entry
+ expect(defs.size).to be >= 1
defs.each do |definitions|
expect(definitions.schema.fetch("properties")).to have_key("name")
end
@@ -263,7 +263,7 @@ def assert_expected_endpoint
end
it 'can be assigned directly' do
- endpoints_array = [stub.as_null_object]
+ endpoints_array = [double.as_null_object]
config.endpoints = endpoints_array
expect(config.endpoints).to respond_to(:find_definition)
end
@@ -292,12 +292,12 @@ def assert_expected_endpoint
context 'when configured with a static version' do
it 'returns the configured static api version number' do
config.send(set_method, '1.2')
- expect(config.send(get_method, {}, stub.as_null_object)).to eq('1.2')
+ expect(config.send(get_method, {}, double.as_null_object)).to eq('1.2')
end
it 'always returns a string, even when configured as an integer' do
config.send(set_method, 3)
- expect(config.send(get_method, {}, stub.as_null_object)).to eq('3')
+ expect(config.send(get_method, {}, double.as_null_object)).to eq('3')
end
end
@@ -305,19 +305,19 @@ def assert_expected_endpoint
it "returns the blocks's return value" do
config.send(set_method) { |e, _| e[:path][%r|/api/v(\d+)/|, 1] }
expect(
- config.send(get_method, { :path => "/api/v2/foo" }, stub.as_null_object)
+ config.send(get_method, { :path => "/api/v2/foo" }, double.as_null_object)
).to eq('2')
end
it 'always returns a string, even when configured as an integer' do
config.send(set_method) { |*a| 3 }
- expect(config.send(get_method, {}, stub.as_null_object)).to eq('3')
+ expect(config.send(get_method, {}, double.as_null_object)).to eq('3')
end
end
it "raises a helpful error when ##{set_method} has not been configured" do
expect {
- config.send(get_method, {}, stub.as_null_object)
+ config.send(get_method, {}, double.as_null_object)
}.to raise_error(ConfigurationError)
end
end
@@ -335,22 +335,22 @@ def assert_expected_endpoint
end
describe "#api_version" do
- before { config.stub(:warn) }
+ before { allow(config).to receive(:warn) }
it 'configures both request_version and response_version' do
config.api_version '23.14'
- expect(config.request_version_for({}, stub.as_null_object)).to eq('23.14')
- expect(config.response_version_for({}, stub.as_null_object)).to eq('23.14')
+ expect(config.request_version_for({}, double.as_null_object)).to eq('23.14')
+ expect(config.response_version_for({}, double.as_null_object)).to eq('23.14')
end
it 'prints a warning' do
- config.should_receive(:warn).with(/api_version.*request_version.*response_version/)
+ expect(config).to receive(:warn).with(/api_version.*request_version.*response_version/)
config.api_version '1.0'
end
end
describe "#validate_if" do
- before { config.stub(:warn) }
+ before { allow(config).to receive(:warn) }
it 'configures validate_response_if' do
config.validate_if { |a| a }
@@ -359,7 +359,7 @@ def assert_expected_endpoint
end
it 'prints a warning' do
- config.should_receive(:warn).with(/validate_if.*validate_response_if/)
+ expect(config).to receive(:warn).with(/validate_if.*validate_response_if/)
config.validate_if { true }
end
end
View
8 spec/unit/interpol/endpoint_spec.rb
@@ -219,7 +219,7 @@ def build_hash(hash = {})
end
it 'exposes the endpoint name' do
- endpoint.stub(:name => 'e-name')
+ allow(endpoint).to receive(:name).and_return('e-name')
endpoint_def = EndpointDefinition.new(endpoint, version, 'response', build_hash)
expect(endpoint_def.endpoint_name).to eq('e-name')
end
@@ -423,7 +423,7 @@ def new_with(hash)
it 'does not add an extra `null` entry to an existing nullable union type' do
schema['properties']['foo']['type'] = %w[ integer null ]
- ::JSON::Validator.should_receive(:fully_validate_schema) do |schema|
+ expect(::JSON::Validator).to receive(:fully_validate_schema) do |schema|
expect(schema['properties']['foo']['type']).to match_array(%w[ integer null ])
[] # no errors
end
@@ -434,7 +434,7 @@ def new_with(hash)
it 'does not add an extra `null` entry to an existing nullable scalar type' do
schema['properties']['foo']['type'] = 'null'
- ::JSON::Validator.should_receive(:fully_validate_schema) do |schema|
+ expect(::JSON::Validator).to receive(:fully_validate_schema) do |schema|
expect(schema['properties']['foo']['type']).to eq('null')
[] # no errors
end
@@ -784,7 +784,7 @@ def new_with(hash)
describe "#validate!" do
it 'validates against the schema' do
- definition.should_receive(:validate_data!).with(data)
+ expect(definition).to receive(:validate_data!).with(data)
example.validate!
end
end
View
13 spec/unit/interpol/request_params_parser_spec.rb
@@ -291,7 +291,7 @@ def ordered_formats_for(name)
def prevent_validation_failure
# Ensure it gets past the validation so we can get to a case where
# the parser cannot parse the value.
- parser.instance_variable_get(:@validator).stub(:validate!)
+ allow(parser.instance_variable_get(:@validator)).to receive(:validate!)
end
it 'raises an error if none of the unioned types can parse the given value' do
@@ -299,7 +299,7 @@ def prevent_validation_failure
# the parser cannot parse the value.
# Note that it gets pass the validation anyway, but only due to a code
# in json-schema: it does not validate URI strings.
- parser.instance_variable_get(:@validator).stub(:validate!)
+ allow(parser.instance_variable_get(:@validator)).to receive(:validate!)
expect {
parse_with('union' => 'some string')
@@ -309,8 +309,13 @@ def prevent_validation_failure
it 'raises an error when parsing an unrecognized type' do
endpoint_definition_yml.gsub!('string', 'bling')
RequestParamsParser::ParamValidator.any_instance.tap do |pv|
- pv.stub(:build_params_schema)
- pv.stub(:validate!)
+ allow_any_instance_of(
+ Interpol::RequestParamsParser::ParamValidator
+ ).to receive(:build_params_schema)
+
+ allow_any_instance_of(
+ Interpol::RequestParamsParser::ParamValidator
+ ).to receive(:validate!)
end
expect {
View
51 spec/unit/interpol/response_schema_validator_spec.rb
@@ -9,7 +9,7 @@ module Interpol
def configuration
lambda do |config|
- config.stub(:endpoints => definition_finder)
+ allow(config).to receive(:endpoints).and_return(definition_finder)
config.response_version '1.0' unless response_version_configured?(config)
config.validate_response_if(&validate_response_if_block) if validate_response_if_block
config.validation_mode = validation_mode
@@ -27,8 +27,8 @@ def validate_response_if(&block)
end
let(:closable_body) do
- stub(:close => nil).tap do |s|
- s.stub(:each).and_yield('{"a":"b"}')
+ double(:close => nil).tap do |s|
+ allow(s).to receive(:each).and_yield('{"a":"b"}')
end
end
@@ -78,13 +78,13 @@ def validate_response_if(&block)
let(:default_definition_finder) { instance_double("Interpol::DefinitionFinder") }
def stub_lookup(v = validator)
- default_definition_finder.stub(:find_definition => v)
+ allow(default_definition_finder).to receive(:find_definition).and_return(v)
end
it 'validates the data against the correct versioned endpoint definition' do
- validator.should_receive(:validate_data!).with("a" => "b")
+ expect(validator).to receive(:validate_data!).with("a" => "b")
- default_definition_finder.should_receive(:find_definition).
+ expect(default_definition_finder).to receive(:find_definition).
with("GET", "/search/200/overview", "response", 200).
and_return(validator)
@@ -105,7 +105,8 @@ def stub_lookup(v = validator)
end
it 'calls the response_version hook with the rack env, the endpoint and the response triplet' do
- endpoint.stub(:method => :get, :route_matches? => true)
+ allow(endpoint).to receive(:method).and_return(:get)
+ allow(endpoint).to receive(:route_matches?).and_return(true)
self.definition_finder = [endpoint].extend(Interpol::DefinitionFinder)
yielded_args = nil
@@ -142,27 +143,27 @@ def stub_lookup(v = validator)
it 'does not validate if the validate_response_if config returns false' do
validate_response_if { |*args| false }
- validator.should_not_receive(:validate_data!)
- default_definition_finder.should_not_receive(:find_definition)
+ expect(validator).not_to receive(:validate_data!)
+ expect(default_definition_finder).not_to receive(:find_definition)
get '/search/200/overview'
end
context 'when no validate_response_if callback has been set' do
it 'does not validate if the response is not 2xx' do
- validator.should_not_receive(:validate_data!)
- default_definition_finder.should_not_receive(:find_definition)
+ expect(validator).not_to receive(:validate_data!)
+ expect(default_definition_finder).not_to receive(:find_definition)
get '/not_found'
end
it 'does not validate a 204 no content response' do
- validator.should_not_receive(:validate_data!)
- default_definition_finder.should_not_receive(:find_definition)
+ expect(validator).not_to receive(:validate_data!)
+ expect(default_definition_finder).not_to receive(:find_definition)
get '/search/204/overview'
end
it 'does not validate a non json response' do
- validator.should_not_receive(:validate_data!)
- default_definition_finder.should_not_receive(:find_definition)
+ expect(validator).not_to receive(:validate_data!)
+ expect(default_definition_finder).not_to receive(:find_definition)
get '/not_json'
expect(last_response.status).to eq(200)
end
@@ -170,7 +171,7 @@ def stub_lookup(v = validator)
it 'closes the body when done iterating it as per the rack spec' do
stub_lookup
- closable_body.should_receive(:close).once
+ expect(closable_body).to receive(:close).once
get '/closable/body'
end
@@ -178,21 +179,21 @@ def stub_lookup(v = validator)
before { set_validation_mode :error }
it 'raises an error when the data fails validation' do
- validator.should_receive(:validate_data!).and_raise(ValidationError)
+ expect(validator).to receive(:validate_data!).and_raise(ValidationError)
stub_lookup
expect { get '/search/200/overview' }.to raise_error(ValidationError)
end
it 'raises an error when no endpoint definition can be found' do
- validator.stub(:validate_data!)
+ allow(validator).to receive(:validate_data!)
stub_lookup(DefinitionFinder::NoDefinitionFound)
expect { get '/search/200/overview' }.to raise_error(NoEndpointDefinitionFoundError)
end
it 'does not raise an error when the data passes validation' do
- validator.stub(:validate_data!)
+ allow(validator).to receive(:validate_data!)
stub_lookup
get '/search/200/overview'
@@ -204,26 +205,26 @@ def stub_lookup(v = validator)
before { set_validation_mode :warn }
it 'prints a warning when the data fails validation' do
- validator.should_receive(:validate_data!).and_raise(ValidationError)
+ expect(validator).to receive(:validate_data!).and_raise(ValidationError)
stub_lookup
- warner.should_receive(:warn).with(/Found.*error.*when validating/)
+ expect(warner).to receive(:warn).with(/Found.*error.*when validating/)
get '/search/200/overview'
end
it 'prints a warning when no endpoint definition can be found' do
- validator.stub(:validate_data!)
+ allow(validator).to receive(:validate_data!)
stub_lookup(DefinitionFinder::NoDefinitionFound)
- warner.should_receive(:warn).with(/No endpoint definition could be found/)
+ expect(warner).to receive(:warn).with(/No endpoint definition could be found/)
get '/search/200/overview'
end
it 'does not print a warning when the data passes validation' do
- validator.stub(:validate_data!)
+ allow(validator).to receive(:validate_data!)
stub_lookup
- warner.should_not_receive(:warn)
+ expect(warner).not_to receive(:warn)
get '/search/200/overview'
end
end
View
8 spec/unit/interpol/stub_app_spec.rb
@@ -222,9 +222,9 @@ def parsed_body
end
it 'performs validations by default' do
- endpoint_example.stub(:apply_filters) { endpoint_example }
+ allow(endpoint_example).to receive(:apply_filters) { endpoint_example }
expect(endpoint_example).to respond_to(:validate!).with(0).arguments
- endpoint_example.should_receive(:validate!).with(no_args)
+ expect(endpoint_example).to receive(:validate!).with(no_args)
header 'Response-Version', '1.0'
get '/users/3/projects'
expect(last_response).to be_ok
@@ -233,9 +233,9 @@ def parsed_body
it 'does not perform validates if validations are disabled' do
app.disable :perform_validations
- endpoint_example.stub(:apply_filters) { endpoint_example }
+ allow(endpoint_example).to receive(:apply_filters) { endpoint_example }
expect(endpoint_example).to respond_to(:validate!).with(0).arguments
- endpoint_example.should_not_receive(:validate!)
+ expect(endpoint_example).not_to receive(:validate!)
header 'Response-Version', '1.0'
get '/users/3/projects'
View
2  spec/unit/interpol/test_helper_spec.rb
@@ -115,7 +115,7 @@ def within_group(&block)
end
def run(group)
- group.run(stub.as_null_object)
+ group.run(double.as_null_object)
end
def num_tests_from(group)
Please sign in to comment.
Something went wrong with that request. Please try again.