Skip to content

Commit

Permalink
Merge pull request #13 from matthewshafer/mshafer/rspec3
Browse files Browse the repository at this point in the history
RSpec 3.1 support
  • Loading branch information
matthewshafer committed Jan 5, 2015
2 parents eeca835 + 96462a4 commit 9fd3f6d
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 80 deletions.
4 changes: 3 additions & 1 deletion spec/shared_examples_for_find.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
shared_examples 'the find method' do
require 'spec_helper'

RSpec.shared_examples_for 'the find method' do
context 'when looking up a valid item' do
it 'returns data on the item' do
expect(context.find(valid_items.first)).to eql(valid_responses.first)
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
def stub_get(path)
stub_request(:get, 'http://api.brewerydb.com/v2/' + path)
end

RSpec.configure(&:disable_monkey_patching!)
10 changes: 5 additions & 5 deletions spec/tankard/api/adjunct_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Adjunct do
RSpec.describe Tankard::Api::Adjunct do
let(:adjunct) { Tankard::Api::Adjunct.new(@request) }

before do
Expand All @@ -9,10 +9,10 @@

describe '#find' do
before do
@request.stub(:get).with('adjunct/valid1', {}).and_return('data' => 'valid1_found')
@request.stub(:get).with('adjunct/valid2', {}).and_return('data' => 'valid2_found')
@request.stub(:get).with('adjunct/invalid1', {}).and_raise(Tankard::Error::HttpError)
@request.stub(:get).with('adjunct/invalid2', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('adjunct/valid1', {}).and_return('data' => 'valid1_found')
allow(@request).to receive(:get).with('adjunct/valid2', {}).and_return('data' => 'valid2_found')
allow(@request).to receive(:get).with('adjunct/invalid1', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('adjunct/invalid2', {}).and_raise(Tankard::Error::HttpError)
end

it_should_behave_like 'the find method' do
Expand Down
2 changes: 1 addition & 1 deletion spec/tankard/api/adjuncts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Adjuncts do
RSpec.describe Tankard::Api::Adjuncts do
let(:adjuncts) { Tankard::Api::Adjuncts.new(@request) }

before do
Expand Down
14 changes: 7 additions & 7 deletions spec/tankard/api/beer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Beer do
RSpec.describe Tankard::Api::Beer do
let(:beer) { Tankard::Api::Beer.new(@request) }

before do
Expand All @@ -9,10 +9,10 @@

describe '#find' do
before do
@request.stub(:get).with('beer/valid1', {}).and_return('data' => 'valid1_found')
@request.stub(:get).with('beer/valid2', {}).and_return('data' => 'valid2_found')
@request.stub(:get).with('beer/invalid1', {}).and_raise(Tankard::Error::HttpError)
@request.stub(:get).with('beer/invalid2', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('beer/valid1', {}).and_return('data' => 'valid1_found')
allow(@request).to receive(:get).with('beer/valid2', {}).and_return('data' => 'valid2_found')
allow(@request).to receive(:get).with('beer/invalid1', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('beer/invalid2', {}).and_raise(Tankard::Error::HttpError)
end

it_should_behave_like 'the find method' do
Expand Down Expand Up @@ -224,8 +224,8 @@

describe '#http_request_uri' do
before do
beer.stub(:route).and_return('beer')
beer.stub(:raise_if_no_id_in_options).and_return('123')
allow(beer).to receive(:route).and_return('beer')
allow(beer).to receive(:raise_if_no_id_in_options).and_return('123')
end

context 'no endpoint is set' do
Expand Down
2 changes: 1 addition & 1 deletion spec/tankard/api/beers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Beers do
RSpec.describe Tankard::Api::Beers do
let(:beers) { Tankard::Api::Beers.new(@request) }

before do
Expand Down
4 changes: 2 additions & 2 deletions spec/tankard/api/categories_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Categories do
RSpec.describe Tankard::Api::Categories do
let(:categories) { Tankard::Api::Categories.new(@request) }

before do
Expand All @@ -9,7 +9,7 @@

describe 'when making a request' do
it 'returns the data portion of the request' do
@request.stub(:get).with('categories', {}).and_return('data' => %w(test1 test2))
allow(@request).to receive(:get).with('categories', {}).and_return('data' => %w(test1 test2))
expect(categories.map { |x| x }).to eql(%w(test1 test2))
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/tankard/api/category_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Category do
RSpec.describe Tankard::Api::Category do
let(:category) { Tankard::Api::Category.new(@request) }

before do
Expand All @@ -9,10 +9,10 @@

describe '#find' do
before do
@request.stub(:get).with('category/1', {}).and_return('data' => 'valid1_found')
@request.stub(:get).with('category/2', {}).and_return('data' => 'valid2_found')
@request.stub(:get).with('category/3', {}).and_raise(Tankard::Error::HttpError)
@request.stub(:get).with('category/4', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('category/1', {}).and_return('data' => 'valid1_found')
allow(@request).to receive(:get).with('category/2', {}).and_return('data' => 'valid2_found')
allow(@request).to receive(:get).with('category/3', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('category/4', {}).and_raise(Tankard::Error::HttpError)
end

it_should_behave_like 'the find method' do
Expand Down
10 changes: 5 additions & 5 deletions spec/tankard/api/search_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Search do
RSpec.describe Tankard::Api::Search do
let(:search) { Tankard::Api::Search.new(@request) }

before do
Expand Down Expand Up @@ -126,15 +126,15 @@

describe '#each' do
it 'should call raise_if_required_options_not_set' do
search.stub(:find_on_single_or_all_pages).and_return(nil)
search.should_receive(:raise_if_required_options_not_set)
allow(search).to receive(:find_on_single_or_all_pages).and_return(nil)
expect(search).to receive(:raise_if_required_options_not_set)
search.each
end

it 'calls the super object with the block' do
block = -> x { x }
search.stub(:raise_if_required_options_not_set).and_return(nil)
search.should_receive(:find_on_single_or_all_pages)
allow(search).to receive(:raise_if_required_options_not_set).and_return(nil)
expect(search).to receive(:find_on_single_or_all_pages)
search.each(&block)
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/tankard/api/style_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Style do
RSpec.describe Tankard::Api::Style do
let(:style) { Tankard::Api::Style.new(@request) }

before do
Expand All @@ -9,10 +9,10 @@

describe '#find' do
before do
@request.stub(:get).with('style/1', {}).and_return('data' => 'valid1_found')
@request.stub(:get).with('style/2', {}).and_return('data' => 'valid2_found')
@request.stub(:get).with('style/3', {}).and_raise(Tankard::Error::HttpError)
@request.stub(:get).with('style/4', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('style/1', {}).and_return('data' => 'valid1_found')
allow(@request).to receive(:get).with('style/2', {}).and_return('data' => 'valid2_found')
allow(@request).to receive(:get).with('style/3', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('style/4', {}).and_raise(Tankard::Error::HttpError)
end

it_should_behave_like 'the find method' do
Expand Down
4 changes: 2 additions & 2 deletions spec/tankard/api/styles_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Styles do
RSpec.describe Tankard::Api::Styles do
let(:styles) { Tankard::Api::Styles.new(@request) }

before do
Expand All @@ -9,7 +9,7 @@

describe 'when making a request' do
it 'returns the data portion of the request' do
@request.stub(:get).with('styles', {}).and_return('data' => %w(test1 test2))
allow(@request).to receive(:get).with('styles', {}).and_return('data' => %w(test1 test2))
expect(styles.map { |x| x }).to eql(%w(test1 test2))
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/tankard/api/utils/find_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Utils::Find do
RSpec.describe Tankard::Api::Utils::Find do
let(:find) { Class.new { include Tankard::Api::Utils::Find }.new }

describe '#route' do
Expand Down
32 changes: 16 additions & 16 deletions spec/tankard/api/utils/page_finders_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Utils::PageFinders do
RSpec.describe Tankard::Api::Utils::PageFinders do
let(:finders) { Class.new { include Tankard::Api::Utils::PageFinders }.new }

describe 'private methods' do
Expand Down Expand Up @@ -48,58 +48,58 @@

describe '#find_on_single_page' do
before do
finders.stub(:http_request_uri).and_return('test')
finders.stub(:http_client).and_return(@request)
finders.stub(:call_block_with_data).with(['test'], nil)
allow(finders).to receive(:http_request_uri).and_return('test')
allow(finders).to receive(:http_client).and_return(@request)
allow(finders).to receive(:call_block_with_data).with(['test'], nil)
end

it 'sends response[data] to call_block_with_data' do
finders.stub(:get_request).and_return('data' => ['test'])
allow(finders).to receive(:get_request).and_return('data' => ['test'])
finders.send(:find_on_single_page, {}, nil)
end

it 'returns 0 when number of pages is not set' do
finders.stub(:get_request).and_return('data' => ['test'])
allow(finders).to receive(:get_request).and_return('data' => ['test'])
expect(finders.send(:find_on_single_page, {}, nil)).to eql(0)
end

it 'returns a value when number of pages is set' do
finders.stub(:get_request).and_return('data' => ['test'], 'numberOfPages' => '3')
allow(finders).to receive(:get_request).and_return('data' => ['test'], 'numberOfPages' => '3')
expect(finders.send(:find_on_single_page, {}, nil)).to eql(3)
end
end

describe '#find_on_all_pages' do
it 'only sets the page when the page is greater than 1' do
finders.should_receive(:find_on_single_page).with({}, nil).and_return(2)
finders.should_not_receive(:find_on_single_page).with({ p: 1 }, nil)
finders.should_receive(:find_on_single_page).with({ p: 2 }, nil).and_return(2)
expect(finders).to receive(:find_on_single_page).with({}, nil).and_return(2)
expect(finders).not_to receive(:find_on_single_page).with({ p: 1 }, nil)
expect(finders).to receive(:find_on_single_page).with({ p: 2 }, nil).and_return(2)

finders.send(:find_on_all_pages, {}, nil)
end
end

describe '#find_on_single_or_all_pages' do
it 'calls find_with_options when a page is set in options' do
finders.should_receive(:find_on_single_page).with({ p: 2 }, nil)
expect(finders).to receive(:find_on_single_page).with({ p: 2 }, nil)
finders.send(:find_on_single_or_all_pages, { p: 2 }, nil)
end

it 'calls find_on_all_pages when a page is not set in options' do
finders.should_receive(:find_on_all_pages).with({}, nil)
expect(finders).to receive(:find_on_all_pages).with({}, nil)
finders.send(:find_on_single_or_all_pages, {}, nil)
end
end

describe '#each' do
before do
finders.stub(:http_request_uri).and_return('test')
finders.stub(:http_client).and_return(nil)
finders.stub(:http_request_parameters).and_return({})
allow(finders).to receive(:http_request_uri).and_return('test')
allow(finders).to receive(:http_client).and_return(nil)
allow(finders).to receive(:http_request_parameters).and_return({})
end

it 'calls find_on_single_or_all_pages' do
finders.should_receive(:find_on_single_or_all_pages).with({}, nil)
expect(finders).to receive(:find_on_single_or_all_pages).with({}, nil)
finders.each
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/tankard/api/yeast_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Yeast do
RSpec.describe Tankard::Api::Yeast do
let(:yeast) { Tankard::Api::Yeast.new(@request) }

before do
Expand All @@ -9,10 +9,10 @@

describe '#find' do
before do
@request.stub(:get).with('yeast/1', {}).and_return('data' => 'valid1_found')
@request.stub(:get).with('yeast/2', {}).and_return('data' => 'valid2_found')
@request.stub(:get).with('yeast/3', {}).and_raise(Tankard::Error::HttpError)
@request.stub(:get).with('yeast/4', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('yeast/1', {}).and_return('data' => 'valid1_found')
allow(@request).to receive(:get).with('yeast/2', {}).and_return('data' => 'valid2_found')
allow(@request).to receive(:get).with('yeast/3', {}).and_raise(Tankard::Error::HttpError)
allow(@request).to receive(:get).with('yeast/4', {}).and_raise(Tankard::Error::HttpError)
end

it_should_behave_like 'the find method' do
Expand Down
2 changes: 1 addition & 1 deletion spec/tankard/api/yeasts_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Tankard::Api::Yeasts do
RSpec.describe Tankard::Api::Yeasts do
let(:yeasts) { Tankard::Api::Yeasts.new(@request) }

before do
Expand Down
Loading

0 comments on commit 9fd3f6d

Please sign in to comment.