spec/spidey/strategies/moped_spec.rb in spidey-mongo-0.2.0 vs spec/spidey/strategies/moped_spec.rb in spidey-mongo-0.3.0
- old
+ new
@@ -2,11 +2,11 @@
require 'moped'
describe Spidey::Strategies::Moped do
class TestMopedSpider < Spidey::AbstractSpider
include Spidey::Strategies::Moped
- handle "http://www.cnn.com", :process_home
+ handle 'http://www.cnn.com', :process_home
def result_key(data)
data[:detail_url]
end
end
@@ -19,45 +19,44 @@
result_collection: @db['results'],
error_collection: @db['errors'])
end
after(:each) do
- %w{ urls results errors }.each{ |col| @db[col].drop }
+ %w( urls results errors ).each { |col| @db[col].drop }
end
- it "should add initial URLs to collection" do
- doc = @db['urls'].find(url: "http://www.cnn.com").first
- doc['handler'].should == :process_home
- doc['spider'].should == 'TestMopedSpider'
+ it 'should add initial URLs to collection' do
+ doc = @db['urls'].find(url: 'http://www.cnn.com').first
+ expect(doc['handler']).to eq(:process_home)
+ expect(doc['spider']).to eq('TestMopedSpider')
end
- it "should not add duplicate URLs" do
- @spider.send :handle, "http://www.cnn.com", :process_home
- @db['urls'].find(url: "http://www.cnn.com").count.should == 1
+ it 'should not add duplicate URLs' do
+ @spider.send :handle, 'http://www.cnn.com', :process_home
+ expect(@db['urls'].find(url: 'http://www.cnn.com').count).to eq(1)
end
- it "should add results" do
+ it 'should add results' do
@spider.record detail_url: 'http://www.cnn.com', foo: 'bar'
- @db['results'].find.count.should == 1
+ expect(@db['results'].find.count).to eq(1)
doc = @db['results'].find.first
- doc['detail_url'].should == 'http://www.cnn.com'
- doc['foo'].should == 'bar'
- doc['spider'].should == 'TestMopedSpider'
+ expect(doc['detail_url']).to eq('http://www.cnn.com')
+ expect(doc['foo']).to eq('bar')
+ expect(doc['spider']).to eq('TestMopedSpider')
end
- it "should update existing result" do
+ it 'should update existing result' do
@db['results'].insert key: 'http://foo.bar', detail_url: 'http://foo.bar'
@spider.record detail_url: 'http://foo.bar', foo: 'bar'
- @db['results'].find.count.should == 1
+ expect(@db['results'].find.count).to eq(1)
end
- it "should add error" do
- @spider.add_error error: Exception.new("WTF"), url: "http://www.cnn.com", handler: :blah
+ it 'should add error' do
+ @spider.add_error error: Exception.new('WTF'), url: 'http://www.cnn.com', handler: :blah
doc = @db['errors'].find.first
- doc['error'].should == 'Exception'
- doc['url'].should == 'http://www.cnn.com'
- doc['handler'].should == :blah
- doc['message'].should == 'WTF'
- doc['spider'].should == 'TestMopedSpider'
+ expect(doc['error']).to eq('Exception')
+ expect(doc['url']).to eq('http://www.cnn.com')
+ expect(doc['handler']).to eq(:blah)
+ expect(doc['message']).to eq('WTF')
+ expect(doc['spider']).to eq('TestMopedSpider')
end
-
-end
\ No newline at end of file
+end