Skip to content

Commit

Permalink
Merge branch 'test-unit-to-rspec'
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
bwillis committed Dec 2, 2014
2 parents 4d2fc85 + debc005 commit c076d04
Show file tree
Hide file tree
Showing 70 changed files with 766 additions and 581 deletions.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format=progress
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

Bug Fixes:

* None
* When an invalid version is received an unsupported exception is raised (#34)

Enhancements:

* None
* Migrate from test-unit to rspec (#37)

Deprecations:

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ We really like when people not only discover something they want added/fixed/rem
Version Cake supports multiple versions of Rails with Appriasals. These will be automatically tested against several ruby versions on CI. If you need to debug a problem, or want to be dilegent and run all of these do the following:

* Install the gems for all supported Rails versions: `bundle exec rake appraisal:install`
* Run all the tests for the supported Rails versions: `bundle exec rake appraisal test`
* Run all the tests for the supported Rails versions: `bundle exec rake appraisal spec`
29 changes: 23 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ GEM
rest-client
simplecov (>= 0.7)
thor
diff-lcs (1.2.5)
erubis (2.7.0)
i18n (0.6.9)
json (1.8.1)
metaclass (0.0.1)
mime-types (1.23)
minitest (5.3.3)
mocha (0.14.0)
metaclass (~> 0.0.1)
multi_json (1.9.2)
rack (1.5.2)
rack-test (0.6.2)
Expand All @@ -56,11 +54,30 @@ GEM
rake (10.0.4)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
test-unit (2.5.5)
thor (0.18.1)
thread_safe (0.3.3)
tzinfo (1.1.0)
Expand All @@ -72,7 +89,7 @@ PLATFORMS
DEPENDENCIES
appraisal
coveralls
mocha
rake
test-unit
rspec
rspec-rails
versioncake!
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Keeping releases consistent is important so here are the steps to follow when pushing a new version.

1. Bump [lib/versioncake/version.rb](https://github.com/bwillis/versioncake/blob/master/lib/versioncake/version.rb) to the next major.minor version
2. Make sure all tests are passing ```bundle && rake && rake appraisal test```
2. Make sure all tests are passing ```bundle && rake && rake appraisal spec```
3. Smoke test in 350-rest-api-versioning/store-after-versioncake

Verify:
Expand Down
10 changes: 3 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ require 'rake/dsl_definition'
require 'bundler'
Bundler.setup

require 'rake/testtask'
require 'rspec/core/rake_task'
require 'appraisal'

Bundler::GemHelper.install_tasks

task :default => :test
RSpec::Core::RakeTask.new(:spec)

Rake::TestTask.new do |i|
i.libs << 'test'
i.test_files = FileList['test/**/*_test.rb']
i.verbose = true
end
task :default => :spec
29 changes: 23 additions & 6 deletions gemfiles/rails3.2.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ GEM
rest-client
simplecov (>= 0.7)
thor
diff-lcs (1.2.5)
erubis (2.7.0)
hike (1.2.2)
i18n (0.6.1)
journey (1.0.4)
json (1.8.0)
metaclass (0.0.1)
mime-types (1.23)
mocha (0.14.0)
metaclass (~> 0.0.1)
multi_json (1.7.3)
rack (1.4.5)
rack-cache (1.2)
Expand All @@ -66,6 +64,26 @@ GEM
json (~> 1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
Expand All @@ -75,7 +93,6 @@ GEM
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
test-unit (2.5.5)
thor (0.18.1)
thread_safe (0.3.3)
tilt (1.4.1)
Expand All @@ -90,8 +107,8 @@ DEPENDENCIES
activesupport (~> 3.2.0)
appraisal
coveralls
mocha
railties (~> 3.2.0)
rake
test-unit
rspec
rspec-rails
versioncake!
29 changes: 23 additions & 6 deletions gemfiles/rails4.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ GEM
rest-client
simplecov (>= 0.7)
thor
diff-lcs (1.2.5)
erubis (2.7.0)
i18n (0.6.4)
metaclass (0.0.1)
mime-types (1.23)
minitest (4.7.5)
mocha (0.14.0)
metaclass (~> 0.0.1)
multi_json (1.7.7)
rack (1.5.2)
rack-test (0.6.2)
Expand All @@ -53,11 +51,30 @@ GEM
rake (10.1.0)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
test-unit (2.5.5)
thor (0.18.1)
thread_safe (0.1.0)
atomic
Expand All @@ -71,8 +88,8 @@ DEPENDENCIES
activesupport (~> 4.0.0)
appraisal
coveralls
mocha
railties (~> 4.0.0)
rake
test-unit
rspec
rspec-rails
versioncake!
29 changes: 23 additions & 6 deletions gemfiles/rails4.1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ GEM
simplecov (>= 0.7)
term-ansicolor
thor
diff-lcs (1.2.5)
docile (1.1.3)
erubis (2.7.0)
i18n (0.6.9)
json (1.8.1)
metaclass (0.0.4)
mime-types (2.2)
minitest (5.3.3)
mocha (1.0.0)
metaclass (~> 0.0.1)
multi_json (1.9.2)
rack (1.5.2)
rack-test (0.6.2)
Expand All @@ -57,14 +55,33 @@ GEM
rake (10.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-rails (3.1.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
simplecov (0.8.2)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
term-ansicolor (1.3.0)
tins (~> 1.0)
test-unit (2.5.5)
thor (0.19.1)
thread_safe (0.3.3)
tins (1.1.0)
Expand All @@ -79,8 +96,8 @@ DEPENDENCIES
activesupport (~> 4.1.0)
appraisal
coveralls
mocha
railties (~> 4.1.0)
rake
test-unit
rspec
rspec-rails
versioncake!
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions spec/integration/controller/custom_strategy_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'
require 'rails_helper'

describe RendersController, type: :controller do
render_views

before do
allow_any_instance_of(VersionCake::Configuration).to \
receive(:extraction_strategy).and_return(lambda { |_| 2 })
end

subject(:render_response) { get :index }

it { expect(render_response.body).to eq 'template v2' }
end
30 changes: 30 additions & 0 deletions spec/integration/controller/multiple_strategy_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'
require 'rails_helper'

describe RendersController, type: :controller do
render_views
let(:request_options) { {} }
subject(:response) { get :index, request_options }

context 'with a version in the accept header' do
before { allow(request).to receive(:headers).and_return({'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=1'}) }

it { expect(response.body).to eq 'template v1' }
end

context 'when query parameter sets the version' do
let(:request_options) { { 'api_version' => '1' } }

it 'renders the query parameter when accept parameter isn\'t available' do
expect(response.body).to eq 'template v1'
end

context 'and the accept header sets the version' do
before { allow(request).to receive(:headers).and_return({'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8;api_version=2'}) }

it 'renders the higher priority accept parameter version' do
expect(response.body).to eq 'template v2'
end
end
end
end
38 changes: 38 additions & 0 deletions spec/integration/controller/regression_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'
require 'rails_helper'
require 'yaml'

describe RendersController, type: :controller do
test_cases = YAML.load(File.open('./spec/fixtures/test_cases.yml'))
test_cases.each do |test_case|
context 'for a test case' do
render_views
before do
allow(@request).to receive(:headers).and_return(headers)
controller.versioned_request = nil # clear out the versioned request so it's not cached
end

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

it "test yml test cases" do
begin
send(method, :index, params)
expect(response.body).to(eq(test_response), custom_message(headers, params, method, response.body, test_response))
rescue => e
raise custom_message(headers, params, method, response.body, test_response) + ", but it failed with an exception '#{e.message}'"
end
end
end
end

def custom_message(headers, params, method, actual_response, expected_response)
data = []
data << "headers:#{headers}" if headers
data << "params:#{params}" if params
"Expected #{data.join(',')} with method #{method} to yield '#{expected_response}', but got '#{actual_response}'"
end
end
Loading

0 comments on commit c076d04

Please sign in to comment.