Permalink
Browse files

Merge pull request #28 from seomoz/handle_trailing_slash

Fix route regex so that it can match when there is a trailing slash.
  • Loading branch information...
myronmarston committed Jun 11, 2013
2 parents f6792af + 00a943b commit bfae9d868840212899a00eca8f505546986d9100
View
@@ -13,6 +13,8 @@ gem 'compass_twitter_bootstrap', :git => 'git://github.com/vwall/compass-twitter
gem 'json', :platform => 'ruby_18'
-gem 'cane', '~> 2.0', :platform => 'ruby_19'
+gem 'cane', '~> 2.6', :platform => 'ruby_19'
+
+# 1.6 won't install on JRuby or 1.8.7 :(.
+gem 'nokogiri', '~> 1.5.10'
-gem 'rspec-fire', :git => 'git://github.com/xaviershay/rspec-fire.git'
View
@@ -19,10 +19,9 @@ Gem::Specification.new do |gem|
gem.add_dependency 'rack'
gem.add_dependency 'json-schema', '~> 1.1.1'
- gem.add_dependency 'nokogiri', '~> 1.5'
gem.add_development_dependency 'rspec', '~> 2.13'
- gem.add_development_dependency 'rspec-fire', '~> 0.4'
+ gem.add_development_dependency 'rspec-fire', '~> 1.2'
gem.add_development_dependency 'simplecov', '~> 0.6'
gem.add_development_dependency 'tailor', '~> 0'
gem.add_development_dependency 'rake', '~> 0.9.2.2'
View
@@ -1,6 +1,8 @@
require "interpol/configuration"
require "interpol/version"
+# The Interpol namespace. Provides only the default configuration.
+# Each of the tools is self-contained and should be required independently.
module Interpol
extend self
@@ -5,6 +5,8 @@
require 'uri'
module Interpol
+ # Meant to be extended onto an array, to provide custom
+ # finder methods for interpol endpoint definitions.
module DefinitionFinder
include HashFetcher
NoDefinitionFound = Class.new
@@ -1,6 +1,7 @@
require 'nokogiri'
module Interpol
+ # Renders HTML documentation for an interpol endpoint.
module Documentation
extend self
@@ -4,6 +4,7 @@
require 'nokogiri'
module Interpol
+ # Provides the interpol documentation app.
module DocumentationApp
extend self
@@ -61,6 +62,7 @@ def inline_asset(tag, tag_type, filename, attributes = {})
private
+ # Helper methods for the documentation app.
module Helpers
def interpol_config
self.class.interpol_config
View
@@ -52,6 +52,8 @@ class << self
end
module Interpol
+ # Provides a helper method for fetching an item from a hash.
+ # Deals with differences on different ruby interpretters.
module HashFetcher
# Unfortunately, on JRuby 1.9, the error raised from Hash#fetch when
# the key is not found does not include the key itself :(. So we work
@@ -146,7 +148,7 @@ def route_regex
end
end.join('\/')
- /\A#{regex_string}\z/
+ /\A#{regex_string}\/?\z/
end
end
@@ -122,6 +122,7 @@ def request_params_invalid(error)
end
end
+ # Contains methods that override sinatra methods.
module SinatraOverriddes
extend Forwardable
def_delegators :settings, :request_params_parser
View
@@ -3,6 +3,7 @@
require 'json'
module Interpol
+ # Public: Builds an interpol stub app.
module StubApp
extend self
@@ -4,6 +4,7 @@
module Interpol
module TestHelper
+ # Defines methods that are used by both the RSpec and Test::Unit mixins.
module Common
def define_interpol_example_tests(&block)
config = Configuration.default.customized_duplicate(&block)
@@ -57,6 +58,7 @@ def filtered_example(config, endpoint, example)
end
end
+ # An RSpec mixin for defining interpol example tests.
module RSpec
include Common
@@ -65,6 +67,7 @@ def define_test(name, &block)
end
end
+ # A Test::Unit mixin for defining interpol example tests.
module TestUnit
include Common
@@ -158,6 +158,10 @@ def endpoint(route)
expect(endpoint('/foo/bar').route_matches?('/foo/bar')).to be_true
end
+ it 'can match when there is a trailing slash' do
+ expect(endpoint('/foo/bar').route_matches?('/foo/bar/')).to be_true
+ end
+
it 'correctly identifies a non match' do
expect(endpoint('/foo/bar').route_matches?('/goo/bar')).to be_false
end
@@ -205,7 +209,7 @@ def build_hash(hash = {})
let(:version) { '1.0' }
let(:config) { Configuration.new }
let(:endpoint) do
- fire_double("Interpol::Endpoint", :name => 'my-endpoint',
+ instance_double("Interpol::Endpoint", :name => 'my-endpoint',
:configuration => config).as_null_object
end
@@ -753,7 +757,7 @@ def new_with(hash)
describe EndpointExample do
- let(:definition) { fire_double("Interpol::EndpointDefinition") }
+ let(:definition) { instance_double("Interpol::EndpointDefinition") }
let(:data) { { "the" => "data" } }
let(:example) { EndpointExample.new(data, definition) }
@@ -73,9 +73,9 @@ def validate_response_if(&block)
end
end
- let(:validator) { fire_double("Interpol::EndpointDefinition", :validate_data! => nil) }
+ let(:validator) { instance_double("Interpol::EndpointDefinition", :validate_data! => nil) }
let(:endpoint) { new_endpoint }
- let(:default_definition_finder) { fire_double("Interpol::DefinitionFinder") }
+ let(:default_definition_finder) { instance_double("Interpol::DefinitionFinder") }
def stub_lookup(v = validator)
default_definition_finder.stub(:find_definition => v)

0 comments on commit bfae9d8

Please sign in to comment.