usaidwat 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ {"kind": "Listing", "data": {"modhash": "", "children": [], "after": null, "before": null}}
@@ -2,8 +2,10 @@ require 'sinatra/base'
2
2
 
3
3
  class Reddit < Sinatra::Base
4
4
  get '/user/*/comments.json' do
5
+ user = params[:splat].first
6
+ puts user
5
7
  root = File.expand_path('../../', __FILE__)
6
- json = File.read(File.join(root, 'fixtures', 'comments.json'))
8
+ json = File.read(File.join(root, 'fixtures', "#{user}.json"))
7
9
  content_type :json
8
10
  json
9
11
  end
@@ -24,7 +24,13 @@ module USaidWat
24
24
  exit 0
25
25
  end
26
26
 
27
+ def quit(message, code=0)
28
+ puts message
29
+ exit code
30
+ end
31
+
27
32
  def list_all_comments
33
+ quit "#{@redditor.username} has no comments." if @redditor.comments.empty?
28
34
  formatter = USaidWat::CLI::CommentFormatter.new
29
35
  @redditor.comments.each { |c| print formatter.format(c) }
30
36
  end
@@ -32,16 +38,13 @@ module USaidWat
32
38
  def list_comments_for_subreddit(subreddit)
33
39
  comments = @redditor.comments
34
40
  comments = comments.reject { |c| c.subreddit != subreddit }
35
- if comments.length == 0
36
- puts "No comments by #{@redditor.username} for #{subreddit}."
37
- exit 0
38
- else
39
- formatter = USaidWat::CLI::CommentFormatter.new
40
- comments.each { |c| print formatter.format(c) }
41
- end
41
+ quit "No comments by #{@redditor.username} for #{subreddit}." if comments.empty?
42
+ formatter = USaidWat::CLI::CommentFormatter.new
43
+ comments.each { |c| print formatter.format(c) }
42
44
  end
43
45
 
44
46
  def tally_comments
47
+ quit "#{@redditor.username} has no comments." if @redditor.comments.empty?
45
48
  # Unfortunately Snooby cannot return comments for a specific
46
49
  # user in a specific subreddit, so for now we have to sort them
47
50
  # ourself.
@@ -19,6 +19,10 @@ module USaidWat
19
19
  raise ReachabilityError, "Reddit unreachable"
20
20
  end
21
21
 
22
+ def to_s
23
+ "#{username}"
24
+ end
25
+
22
26
  private
23
27
  def enable_test_urls
24
28
  Snooby::Paths.each { |k,v| Snooby::Paths[k] = v.sub(%r{http://www.reddit.com}, "http://localhost:4567") }
@@ -16,7 +16,7 @@ module USaidWat
16
16
  out.write("#{comment.subreddit}\n".color(:green))
17
17
  out.write("#{comment_link(comment)}\n".color(:yellow))
18
18
  out.write("\n")
19
- out.write("#{comment.body}\n")
19
+ out.write("#{comment.body.strip}\n")
20
20
  @count += 1
21
21
  out.rewind
22
22
  out.read
@@ -1,3 +1,3 @@
1
1
  module USaidWat
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -11,13 +11,19 @@ module USaidWat
11
11
  end
12
12
  end
13
13
 
14
+ describe "#to_s" do
15
+ it "returns a string representing the Redditor" do
16
+ "#{redditor}".should == "mipadi"
17
+ end
18
+ end
19
+
14
20
  context "when Reddit is up" do
15
21
  before(:each) do
16
22
  WebMock.disable_net_connect!
17
23
  WebMock.reset!
18
24
  root = File.expand_path("../../../features/fixtures", __FILE__)
19
25
  stub_request(:get, "http://www.reddit.com/user/mipadi/comments.json?after=&limit=100").
20
- to_return(:body => IO.read(File.join(root, "comments.json")))
26
+ to_return(:body => IO.read(File.join(root, "mipadi.json")))
21
27
  end
22
28
 
23
29
  describe "#comments" do
@@ -40,6 +40,17 @@ EXPECTED
40
40
  lines[1].should == ''
41
41
  lines[2].should_not == ""
42
42
  end
43
+
44
+ it "should strip leading and trailing whitespace from comments" do
45
+ comment = double(comment)
46
+ comment.should_receive(:subreddit).twice.and_return("test")
47
+ comment.should_receive(:link_id).and_return("t3_13f783")
48
+ comment.should_receive(:id).and_return("c73qhxi")
49
+ comment.should_receive(:body).and_return("This is a comment.\n\nIt has two lines.\n\n\n")
50
+ s = formatter.format(comment)
51
+ lines = s.split("\n")
52
+ lines[-1].should == "It has two lines."
53
+ end
43
54
  end
44
55
  end
45
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usaidwat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-14 00:00:00.000000000 Z
12
+ date: 2012-12-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: snooby
@@ -138,7 +138,8 @@ files:
138
138
  - Rakefile
139
139
  - bin/usaidwat
140
140
  - features/browse.feature
141
- - features/fixtures/comments.json
141
+ - features/fixtures/blank.json
142
+ - features/fixtures/mipadi.json
142
143
  - features/help.feature
143
144
  - features/server/reddit.rb
144
145
  - features/step_definitions/reddit_steps.rb
@@ -172,13 +173,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
173
  version: '0'
173
174
  requirements: []
174
175
  rubyforge_project:
175
- rubygems_version: 1.8.23
176
+ rubygems_version: 1.8.24
176
177
  signing_key:
177
178
  specification_version: 3
178
179
  summary: Answers the age-old question, "Where does a Redditor comment the most?"
179
180
  test_files:
180
181
  - features/browse.feature
181
- - features/fixtures/comments.json
182
+ - features/fixtures/blank.json
183
+ - features/fixtures/mipadi.json
182
184
  - features/help.feature
183
185
  - features/server/reddit.rb
184
186
  - features/step_definitions/reddit_steps.rb
File without changes