Skip to content

Commit e360555

Browse files
committed
Add test coverage rise.
1 parent 222a68d commit e360555

File tree

8 files changed

+142
-125
lines changed

8 files changed

+142
-125
lines changed

plugins/publish/instapaper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def add(url, title = '', selection = '')
3232
Automatic::Log.puts(:info, message)
3333
else
3434
Automatic::Log.puts(:error, "#{res.code} Error: #{url}")
35+
raise
3536
end
3637
end
3738

plugins/subscription/text.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,8 @@ def initialize(config, pipeline=[])
6767
end
6868

6969
def run
70-
retries = 0
71-
begin
72-
if @dummyfeeds != []
73-
@pipeline << Automatic::FeedParser.create(@dummyfeeds)
74-
end
75-
rescue
76-
retries += 1
77-
Automatic::Log.puts("error", "ErrorCount: #{retries}, Fault in parsing: #{feed}")
78-
sleep @config['interval'].to_i unless @config['interval'].nil?
79-
retry if retries <= @config['retry'].to_i unless @config['retry'].nil?
70+
if @dummyfeeds != []
71+
@pipeline << Automatic::FeedParser.create(@dummyfeeds)
8072
end
8173

8274
@pipeline

plugins/subscription/weather.rb

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,14 @@ def initialize(config, pipeline=[])
4242
end
4343

4444
def run
45-
retries = 0
46-
begin
47-
weather = @weather.send(@day)['weather'] unless @weather.send(@day).nil?
48-
if weather != nil
49-
dummyfeed = WeatherFeed.new
50-
dummyfeed.set_title(weather)
51-
dummyfeed.set_link(dummyfeed.link + '.' + @day)
52-
dummyfeeds = []
53-
dummyfeeds << dummyfeed
54-
@pipeline << Automatic::FeedParser.create(dummyfeeds)
55-
end
56-
rescue
57-
retries += 1
58-
Automatic::Log.puts("error", "ErrorCount: #{retries}, Fault in parsing: #{dummyfeed}")
59-
sleep @config['interval'].to_i unless @config['interval'].nil?
60-
retry if retries <= @config['retry'].to_i unless @config['retry'].nil?
45+
weather = @weather.send(@day)['weather'] unless @weather.send(@day).nil?
46+
if weather != nil
47+
dummyfeed = WeatherFeed.new
48+
dummyfeed.set_title(weather)
49+
dummyfeed.set_link(dummyfeed.link + '.' + @day)
50+
dummyfeeds = []
51+
dummyfeeds << dummyfeed
52+
@pipeline << Automatic::FeedParser.create(dummyfeeds)
6153
end
6254

6355
@pipeline

spec/plugins/publish/instapaper_spec.rb

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,43 @@
1212
require 'publish/instapaper'
1313

1414
describe Automatic::Plugin::PublishInstapaper do
15-
subject {
16-
Automatic::Plugin::PublishInstapaper.new(
17-
{ 'email' => "email@example.com",
18-
'password' => "pswd",
19-
'interval' => 5,
20-
'retry' => 5
21-
},
15+
context 'when feed' do
16+
subject {
17+
Automatic::Plugin::PublishInstapaper.new(
18+
{ 'email' => "email@example.com",
19+
'password' => "pswd",
20+
'interval' => 5,
21+
'retry' => 5
22+
},
23+
AutomaticSpec.generate_pipeline{
24+
feed { item "http://github.com" }
25+
}
26+
)
27+
}
28+
29+
it "should post the link in the feed" do
30+
instapaper = mock("instapaper")
31+
instapaper.should_receive(:add).with("http://github.com", nil, '')
32+
subject.instance_variable_set(:@instapaper, instapaper)
33+
subject.run.should have(1).feed
34+
end
35+
end
36+
37+
context 'when feed is empty' do
38+
subject {
39+
Automatic::Plugin::PublishInstapaper.new(
40+
{ 'email' => "email@example.com",
41+
'password' => "pswd",
42+
'interval' => 1,
43+
'retry' => 1
44+
},
2245
AutomaticSpec.generate_pipeline{
23-
feed { item "http://github.com" }
24-
}
46+
feed { item "http://github.com" }
47+
}
2548
)
26-
}
49+
}
2750

28-
it "should post the link in the feed" do
29-
instapaper = mock("instapaper")
30-
instapaper.should_receive(:add).with("http://github.com", nil, '')
31-
subject.instance_variable_set(:@instapaper, instapaper)
32-
subject.run.should have(1).feed
51+
its (:run) { subject.run.should have(1).feed }
3352
end
3453
end
3554

@@ -41,8 +60,8 @@
4160
'password' => "pswd",
4261
'interval' => 5,
4362
'retry' => 5
44-
}
45-
)
63+
}
64+
)
4665
}
4766

4867
url = "http://www.google.com"
@@ -52,17 +71,18 @@
5271
specify {
5372
res = stub("res")
5473
res.should_receive(:code).and_return("201")
55-
5674
subject.should_receive(:request).and_return(res)
5775
subject.add(url, title, description)
5876
}
5977

60-
specify {
61-
res = mock("res")
62-
res.should_receive(:code).twice.and_return("403")
6378

64-
subject.should_receive(:request).and_return(res)
65-
subject.add(url, title, description)
66-
}
79+
it 'raise error' do
80+
lambda{
81+
res = mock("res")
82+
res.should_receive(:code).twice.and_return("403")
83+
subject.should_receive(:request).and_return(res)
84+
subject.add(url, title, description)
85+
}.should raise_error
86+
end
6787
end
6888
end

spec/plugins/publish/pocket_spec.rb

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@
1111
require 'publish/pocket'
1212

1313
describe Automatic::Plugin::PublishPocket do
14-
subject {
15-
Automatic::Plugin::PublishPocket.new(
16-
{ 'consumer_key' => "hugehuge",
17-
'access_token' => "hogehoge",
18-
'interval' => 1,
19-
'retry' => 1
20-
},
14+
context 'return feed' do
15+
subject {
16+
Automatic::Plugin::PublishPocket.new(
17+
{ 'consumer_key' => "hugehuge",
18+
'access_token' => "hogehoge",
19+
'interval' => 1,
20+
'retry' => 1
21+
},
2122
AutomaticSpec.generate_pipeline{
22-
feed { item "http://github.com" }
23-
}
24-
)
25-
}
23+
feed { item "http://github.com" }
24+
}) }
2625

27-
it "should post the link in the feed" do
28-
client = mock("client")
29-
client.should_receive(:add).with(:url => 'http://github.com')
30-
subject.instance_variable_set(:@client, client)
31-
subject.run.should have(1).feed
26+
it "should post the link in the feed" do
27+
client = mock("client")
28+
client.should_receive(:add).with(:url => 'http://github.com')
29+
subject.instance_variable_set(:@client, client)
30+
subject.run.should have(1).feed
31+
end
32+
33+
it "should not post" do
34+
subject.run.should have(1).feed
35+
end
3236
end
33-
end
3437

35-
describe Automatic::Plugin::PublishPocket do
36-
subject {
37-
Automatic::Plugin::PublishPocket.new(
38-
{ 'consumer_key' => "hugehuge",
39-
'access_token' => "hogehoge",
40-
'interval' => 1,
41-
'retry' => 1
42-
},
43-
AutomaticSpec.generate_pipeline{
44-
}
45-
)
46-
}
38+
context 'not return feed' do
39+
subject {
40+
Automatic::Plugin::PublishPocket.new(
41+
{ 'consumer_key' => "hugehuge",
42+
'access_token' => "hogehoge",
43+
'interval' => 1,
44+
'retry' => 1
45+
})}
4746

48-
it "should un post" do
49-
subject.run.should have(0).feed
47+
it "should un post" do
48+
subject.run.should have(0).feed
49+
end
5050
end
5151
end

spec/plugins/publish/twitter_spec.rb

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,63 @@
1111
require 'publish/twitter'
1212

1313
describe Automatic::Plugin::PublishTwitter do
14-
subject {
15-
Automatic::Plugin::PublishTwitter.new(
16-
{ 'consumer_key' => 'your_consumer_key',
17-
'consumer_secret' => 'your_consumer_secret',
18-
'oauth_token' => 'your_oauth_token',
19-
'oauth_token_secret' => 'your_oauth_token_secret',
20-
'interval' => 5,
21-
'retry' => 5
22-
},
23-
AutomaticSpec.generate_pipeline{
14+
context 'when feed' do
15+
describe 'should post the link tweet' do
16+
subject {
17+
Automatic::Plugin::PublishTwitter.new(
18+
{},
19+
AutomaticSpec.generate_pipeline{
2420
feed { item "http://github.com" }
21+
})}
22+
23+
its (:run) {
24+
twitter = mock("twitter")
25+
twitter.should_receive(:update).with(" http://github.com")
26+
subject.instance_variable_set(:@twitter, twitter)
27+
subject.run.should have(1).feed
28+
}
29+
end
30+
31+
describe 'should post the tweet_tmp' do
32+
subject {
33+
Automatic::Plugin::PublishTwitter.new(
34+
{ 'tweet_tmp' => 'publish-twitter'},
35+
AutomaticSpec.generate_pipeline{
36+
feed { item "http://github.com" }
37+
})}
38+
39+
its (:run) {
40+
twitter = mock("twitter")
41+
twitter.should_receive(:update).with("publish-twitter")
42+
subject.instance_variable_set(:@twitter, twitter)
43+
subject.run.should have(1).feed
44+
}
45+
end
46+
47+
describe 'interval & retry was used error' do
48+
subject {
49+
Automatic::Plugin::PublishTwitter.new(
50+
{ 'interval' => 1, 'retry' => 1 },
51+
AutomaticSpec.generate_pipeline{
52+
feed { item "http://github.com" }
53+
})}
54+
55+
its (:run) {
56+
subject.run.should have(1).feed
57+
}
58+
end
59+
end
60+
61+
context 'when feed is empty' do
62+
describe 'should not post' do
63+
subject {
64+
Automatic::Plugin::PublishTwitter.new(
65+
{},
66+
)}
67+
68+
its (:run) {
69+
subject.run.should have(0).feed
2570
}
26-
)
27-
}
28-
29-
it "should post the link tweet" do
30-
twitter = mock("twitter")
31-
twitter.should_receive(:update).with(" http://github.com")
32-
subject.instance_variable_set(:@twitter, twitter)
33-
subject.run.should have(1).feed
71+
end
3472
end
3573
end

spec/plugins/subscription/text_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,4 @@
5151
its(:run) { should have(1).feed }
5252
end
5353

54-
context "with retry to feeds whose invalid URL" do
55-
subject {
56-
Automatic::Plugin::SubscriptionText.new(
57-
{ 'titles' => [],
58-
'retry' => 1,
59-
'interval' => 1
60-
}
61-
)
62-
}
63-
64-
its(:run) { should be_empty }
65-
end
66-
6754
end

spec/plugins/subscription/weather_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,4 @@
4141
its(:run) { should have(1).feed }
4242
end
4343

44-
context "with retry to feeds whose invalid URL" do
45-
subject {
46-
Automatic::Plugin::SubscriptionWeather.new(
47-
{ 'zipcode' => [],
48-
'retry' => 1,
49-
'interval' => 1
50-
}
51-
)
52-
}
53-
54-
its(:run) { should be_empty }
55-
end
56-
5744
end

0 commit comments

Comments
 (0)