Skip to content

Commit 1527d69

Browse files
author
Arjan van der Gaag
committed
Merge remote-tracking branch 'ariejan/master'
Also replaced test task with RSpec task in Rakefile.
2 parents 950e8c9 + db79952 commit 1527d69

10 files changed

+113
-116
lines changed

Rakefile

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
require 'bundler/gem_tasks'
2-
require 'rake/testtask'
2+
require 'rspec/core/rake_task'
33

4-
Rake::TestTask.new do |t|
5-
t.libs << 'spec'
6-
t.test_files = FileList['spec/**/*_spec.rb']
7-
t.verbose = true
8-
end
4+
RSpec::Core::RakeTask.new(:spec)
95

10-
task default: :test
6+
task :default => :spec

bol.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ Gem::Specification.new do |s|
1717
s.require_paths = ['lib']
1818

1919
s.add_development_dependency 'rake'
20+
s.add_development_dependency 'rspec'
2021
s.add_development_dependency 'fakeweb'
21-
s.add_development_dependency 'mocha'
2222
end

spec/bol/category_spec.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,57 @@
44
describe 'combining categories' do
55
it 'should add two categories for a combined scope' do
66
cat = Bol::Category.new(1) + Bol::Category.new(2)
7-
cat.id.must_equal('1+2')
7+
cat.id.should == '1+2'
88
end
99

1010
it 'should not duplicate IDs when adding' do
1111
cat = Bol::Category.new(1) + Bol::Category.new(2) + Bol::Category.new(2)
12-
cat.id.must_equal('1+2')
12+
cat.id.should == '1+2'
1313
end
1414

1515
it 'should subtract two categories to reduce scope' do
1616
a = Bol::Category.new(1) + Bol::Category.new(2)
1717
b = Bol::Category.new(2)
18-
(a - b).id.must_equal('1')
18+
(a - b).id.should == '1'
1919
end
2020
end
2121

2222
describe '#search' do
2323
it 'should default to root category from the class' do
2424
query = Bol::Category.search 'foo'
25-
query.must_be_kind_of Bol::ResultProxy
26-
query.category_id.must_equal 0
25+
query.should be_instance_of Bol::ResultProxy
26+
query.category_id.should == 0
2727
end
2828

2929
it 'should set query term' do
30-
Bol::Requests::Search.expects(:new).with('foo', instance_of(Bol::Query)).returns(stub(proxy: nil, query: nil))
30+
Bol::Requests::Search.should_receive(:new).with('foo', instance_of(Bol::Query)).and_return(stub(proxy: nil, query: nil))
3131
Bol::Category.search 'foo'
3232
end
3333
end
3434

3535
describe 'default category' do
3636
it 'should set request category scope to 0' do
37-
Bol::Category.new.id.must_equal(0)
37+
Bol::Category.new.id.should == 0
3838
end
3939
end
4040

4141
describe 'lists' do
4242
let(:cat) { Bol::Category.new.top_products }
4343

4444
it 'should create a list request' do
45-
cat.must_be_instance_of(Bol::ResultProxy)
45+
cat.should be_instance_of Bol::ResultProxy
4646
end
4747

4848
it 'should be scoped to the category' do
49-
cat.category_id.must_equal(0)
49+
cat.category_id.should == 0
5050
end
5151
end
5252

5353
describe 'subcategories' do
5454
let(:cat) { Bol::Category.new.subcategories }
5555

5656
it 'should create category list request' do
57-
cat.must_be_instance_of(Bol::Requests::Category)
57+
cat.should be_instance_of Bol::Requests::Category
5858
end
5959
end
6060
end

spec/bol/configuration_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
describe 'as a hash' do
55
it 'should should set known keys' do
66
c = Bol::Configuration.new access_key: 'foo'
7-
c[:access_key].must_equal 'foo'
7+
c[:access_key].should == 'foo'
88
end
99

1010
it 'should raise for unknown keys' do
11-
proc { Bol::Configuration.new foo: 'bar' }.must_raise ArgumentError
11+
expect { Bol::Configuration.new foo: 'bar' }.to raise_error ArgumentError
1212
end
1313

1414
it 'should set a single key' do
1515
c = Bol::Configuration.new
1616
c[:access_key] = 'bar'
17-
c[:access_key].must_equal 'bar'
17+
c[:access_key].should == 'bar'
1818
end
1919
end
2020

@@ -23,12 +23,12 @@
2323

2424
it 'should should set known keys' do
2525
config.access_key = 'bar'
26-
config.access_key.must_equal 'bar'
26+
config.access_key.should == 'bar'
2727
end
2828

2929
it 'should raise for unknown keys' do
30-
proc { config.foo = 'bar' }.must_raise NoMethodError
31-
proc { config.foo }.must_raise NoMethodError
30+
expect { config.foo = 'bar' }.to raise_error NoMethodError
31+
expect { config.foo }.to raise_error NoMethodError
3232
end
3333
end
3434
end

spec/bol/product_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
let(:r) { Bol::Product.find(1) }
66

77
before do
8-
Bol.stubs(:configuration).returns({ access_key: 'foo', secret: 'bar' })
8+
Bol.stub(:configuration).and_return({ access_key: 'foo', secret: 'bar' })
99
FakeWeb.register_uri(:get, 'https://openapi.bol.com/openapi/services/rest/catalog/v3/products/1?categoryId=0', body: fixture('products.xml'))
1010
end
1111

1212
it 'should return product instance' do
13-
r.must_be_instance_of Bol::Product
13+
r.should be_instance_of Bol::Product
1414
end
1515

1616
it 'should raise error when not found'
@@ -20,13 +20,13 @@
2020
it 'should delegate [] to attributes' do
2121
product = Bol::Product.new
2222
product.attributes[:foo] = 'bar'
23-
product[:foo].must_equal('bar')
23+
product[:foo].should == 'bar'
2424
end
2525

2626
it 'should expose attributes as methods' do
2727
product = Bol::Product.new
2828
product.attributes[:foo] = 'bar'
29-
product.foo.must_equal('bar')
29+
product.foo.should == 'bar'
3030
end
3131

3232
describe 'referral_url' do
@@ -39,7 +39,7 @@
3939
end
4040

4141
it 'should generate referral URL' do
42-
product.referral_url('foo').must_equal("http://partnerprogramma.bol.com/click/click?p=1&t=url&s=foo&url=http%3A%2F%2Ffoo.bar&f=API&subid=qux&name=bla")
42+
product.referral_url('foo').should == "http://partnerprogramma.bol.com/click/click?p=1&t=url&s=foo&url=http%3A%2F%2Ffoo.bar&f=API&subid=qux&name=bla"
4343
end
4444
end
4545

@@ -53,15 +53,15 @@
5353
end
5454

5555
it 'should return medium by default' do
56-
product.cover.must_equal('foo')
56+
product.cover.should == 'foo'
5757
end
5858

5959
it 'should take format as argument' do
60-
product.cover(:small).must_equal('bar')
60+
product.cover(:small).should == 'bar'
6161
end
6262

6363
it 'should raise on invalid format' do
64-
proc { product.cover(:baz) }.must_raise(KeyError)
64+
expect { product.cover(:baz) }.to raise_error KeyError
6565
end
6666
end
6767
end

spec/bol/query_spec.rb

+27-27
Original file line numberDiff line numberDiff line change
@@ -3,129 +3,129 @@
33
describe Bol::Query do
44
describe 'category scope' do
55
it 'should set category scope' do
6-
Bol::Query.new(1).category_id.must_equal(1)
6+
Bol::Query.new(1).category_id.should == 1
77
end
88

99
it 'should raise unless given a number' do
10-
proc { Bol::Query.new('foo') }.must_raise ArgumentError
10+
expect { Bol::Query.new('foo') }.to raise_error ArgumentError
1111
end
1212

1313
it 'should set category param' do
14-
Bol::Query.new(1).params[:categoryId].must_equal(1)
14+
Bol::Query.new(1).params[:categoryId].should == 1
1515
end
1616
end
1717

1818
describe '#has_param?' do
1919
let(:q) { Bol::Query.new(0) }
2020

2121
it 'should be true when object' do
22-
q.has_param?(:categoryId).must_equal true
22+
q.has_param?(:categoryId).should be_true
2323
end
2424

2525
it 'should be false when nil' do
26-
q.has_param?(:term).must_equal false
26+
q.has_param?(:term).should be_false
2727
end
2828

2929
it 'should be false when not set' do
30-
q.has_param?(:foo).must_equal false
30+
q.has_param?(:foo).should be_false
3131
end
3232
end
3333

3434
describe '#limit' do
3535
let(:q) { Bol::Query.new(0) }
3636

3737
it 'should parse argument to a number' do
38-
q.limit('10').limit.must_equal(10)
38+
q.limit('10').limit.should == 10
3939
end
4040

4141
it 'should add parameter to request' do
4242
q.limit(10)
43-
q.params[:nrProducts].must_equal(10)
43+
q.params[:nrProducts].should == 10
4444
end
4545

4646
it 'should not add parameter when not set' do
47-
q.params.keys.wont_include(:nrProducts)
47+
q.params.keys.should_not include(:nrProducts)
4848
end
4949

5050
it 'should return query' do
51-
q.limit(10).must_equal(q)
51+
q.limit(10).should == q
5252
end
5353
end
5454

5555
describe '#page' do
5656
let(:q) { Bol::Query.new(0).page(2) }
5757

5858
it 'should parse to number' do
59-
Bol::Query.new(0).page('2').limit.must_equal(10)
59+
Bol::Query.new(0).page('2').limit.should == 10
6060
end
6161

6262
it 'should default to 1' do
6363
x = Bol::Query.new(0).page(nil)
64-
x.limit.must_equal(10)
65-
x.offset.must_equal(0)
64+
x.limit.should == 10
65+
x.offset.should == 0
6666
end
6767

6868
it 'should add limit param to request' do
69-
q.limit.must_equal(10)
69+
q.limit.should == 10
7070
end
7171

7272
it 'should add offset param to request' do
73-
q.offset.must_equal(10)
73+
q.offset.should == 10
7474
end
7575

7676
it 'should use per page config to determine offset value' do
7777
Bol.configuration[:per_page] = 20
7878
x = Bol::Query.new(0).page(3)
79-
x.limit.must_equal(20)
80-
x.offset.must_equal(40)
79+
x.limit.should == 20
80+
x.offset.should == 40
8181
Bol.configuration[:per_page] = 10
8282
end
8383

8484
it 'should return query' do
8585
q = Bol::Query.new(0)
86-
q.page(1).must_equal(q)
86+
q.page(1).should == q
8787
end
8888
end
8989

9090
describe '#offset' do
9191
let(:q) { Bol::Query.new(0) }
9292

9393
it 'should parse argument to a number' do
94-
q.offset('10').offset.must_equal(10)
94+
q.offset('10').offset.should == 10
9595
end
9696

9797
it 'should add parameter to request' do
9898
q.offset(10)
99-
q.params[:offset].must_equal(10)
99+
q.params[:offset].should == 10
100100
end
101101

102102
it 'should not add parameter when not set' do
103-
q.params.keys.wont_include(:offset)
103+
q.params.keys.should_not include(:offset)
104104
end
105105

106106
it 'should return query' do
107-
q.offset(10).must_equal(q)
107+
q.offset(10).should == q
108108
end
109109
end
110110

111111
describe '#order' do
112112
let(:q) { Bol::Query.new(0) }
113113

114114
it 'should raise unless wrong format' do
115-
proc { q.order('foo') }.must_raise ArgumentError
115+
expect { q.order('foo') }.to raise_error ArgumentError
116116
end
117117

118118
it 'should add order direction on request' do
119-
q.order('price ASC').params[:sortingAscending].must_equal('true')
120-
q.order('price DESC').params[:sortingAscending].must_equal('false')
119+
q.order('price ASC').params[:sortingAscending].should == 'true'
120+
q.order('price DESC').params[:sortingAscending].should == 'false'
121121
end
122122

123123
it 'should add order key on request' do
124-
q.order('price ASC').params[:sortingMethod].must_equal('price')
124+
q.order('price ASC').params[:sortingMethod].should == 'price'
125125
end
126126

127127
it 'should return query' do
128-
q.order('price ASC').must_equal(q)
128+
q.order('price ASC').should == q
129129
end
130130
end
131131
end

0 commit comments

Comments
 (0)