Skip to content

Commit

Permalink
Regression spec to make sure I didn't break anything
Browse files Browse the repository at this point in the history
  • Loading branch information
bwillis committed Apr 4, 2016
1 parent 3762bd2 commit 2d8eec5
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions spec/integration/rack/middleware_regression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@

describe VersionCake::Rack::Middleware do
let(:app) do
_config = config
rack = Rack::Builder.new do
config = VersionCake::Configuration.new
config.resources { |r| r.resource %r{.*}, [], [], (1..5) }
use VersionCake::Rack::Middleware, config
run lambda { |env| [ 200, {},[ env['versioncake.context'].version ] ] }
use VersionCake::Rack::Middleware, _config
run lambda { |env| [ 200, {},[ "version is #{env['versioncake.context'].version}" ] ] }
end
Rack::MockRequest.new(rack)
end
let(:config) do
config = VersionCake::Configuration.new
config.resources { |r| r.resource %r{.*}, [], [], (1..5) }
config
end

test_cases = YAML.load(File.open('./spec/fixtures/test_cases.yml'))
test_cases.each do |test_case|
context 'for a test case' do


let(:data) { test_case['request'] || {} }
let(:method) { (data['method'] || 'get').to_sym }
let(:headers) { data['headers'] || {} }
let(:params) { data['params'] || {} }
let(:test_response) { test_case['response'] }
let(:test_response) { "version is #{test_case['response']}" }

it "test yml test cases" do
begin
Expand All @@ -40,4 +42,20 @@ def custom_message(headers, params, method, actual_response, expected_response)
data << "params:#{params}" if params
"Expected #{data.join(',')} with method #{method} to yield '#{expected_response}', but got '#{actual_response}'"
end

context 'when configured with unversioned template' do
let(:config) do
config = VersionCake::Configuration.new
config.resources { |r| r.resource %r{.*}, [], [], (1..5) }
config.missing_version = :unversioned_template
config
end

context 'and the request does not contain a version' do
it 'does not include a version (rails will convert nil => unversioned template)' do
_response_status, _response_headers, response = app.request('get', '/renders')
expect(response.body).to eq 'version is ' # nil
end
end
end
end

0 comments on commit 2d8eec5

Please sign in to comment.