Skip to content

Commit 6ea20fe

Browse files
author
Matt Swanson
committed
add tests for fetch_feeds.
1 parent f6bc2c1 commit 6ea20fe

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

‎app/tasks/fetch_feeds.rb‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
require 'thread/pool'
2+
23
require_relative "fetch_feed"
34

45
class FetchFeeds
5-
def initialize(feeds)
6+
def initialize(feeds, pool = Thread.pool(10))
67
@feeds = feeds
8+
@pool = pool
79
end
810

911
def fetch_all
10-
pool = Thread.pool(10)
11-
1212
@feeds.each do |feed|
13-
pool.process do
13+
@pool.process do
1414
FetchFeed.new(feed).fetch
1515
end
1616
end
1717

18-
pool.shutdown
18+
@pool.shutdown
1919
end
2020

2121
def self.enqueue(feeds)

‎spec/tasks/fetch_feeds_spec.rb‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "spec_helper"
2+
3+
describe FetchFeeds do
4+
describe "#fetch_all" do
5+
let(:feeds) { [FeedFactory.build, FeedFactory.build] }
6+
let(:fetcher_one) { stub }
7+
let(:fetcher_two) { stub }
8+
let(:pool) { stub }
9+
10+
it "calls FetchFeed#fetch for every feed" do
11+
pool.stub(:process).and_yield
12+
FetchFeed.stub(:new).and_return(fetcher_one, fetcher_two)
13+
14+
fetcher_one.should_receive(:fetch).once
15+
fetcher_two.should_receive(:fetch).once
16+
17+
pool.should_receive(:shutdown)
18+
19+
FetchFeeds.new(feeds, pool).fetch_all
20+
end
21+
end
22+
end

0 commit comments

Comments
 (0)