octospy 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +23 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +58 -0
  8. data/Rakefile +4 -0
  9. data/bin/octospy +6 -0
  10. data/lib/cinch/plugins/management.rb +91 -0
  11. data/lib/cinch/plugins/octospy/job.rb +97 -0
  12. data/lib/cinch/plugins/octospy/recording.rb +101 -0
  13. data/lib/cinch/plugins/octospy.rb +68 -0
  14. data/lib/octospy/configurable.rb +49 -0
  15. data/lib/octospy/extensions/string.rb +39 -0
  16. data/lib/octospy/octokit/client.rb +9 -0
  17. data/lib/octospy/parser/download.rb +13 -0
  18. data/lib/octospy/parser/gist.rb +20 -0
  19. data/lib/octospy/parser/issue.rb +43 -0
  20. data/lib/octospy/parser/organization.rb +22 -0
  21. data/lib/octospy/parser/pull_request.rb +32 -0
  22. data/lib/octospy/parser/repository.rb +80 -0
  23. data/lib/octospy/parser/user.rb +37 -0
  24. data/lib/octospy/parser/wiki.rb +19 -0
  25. data/lib/octospy/parser.rb +117 -0
  26. data/lib/octospy/recordable/channel.rb +23 -0
  27. data/lib/octospy/recordable/repo.rb +16 -0
  28. data/lib/octospy/recordable.rb +26 -0
  29. data/lib/octospy/shortener.rb +48 -0
  30. data/lib/octospy/version.rb +3 -0
  31. data/lib/octospy/worker.rb +48 -0
  32. data/lib/octospy.rb +55 -0
  33. data/octospy.gemspec +37 -0
  34. data/spec/fixtures/commit_comment_event.json +59 -0
  35. data/spec/fixtures/create_event.json +21 -0
  36. data/spec/fixtures/delete_event.json +23 -0
  37. data/spec/fixtures/follow_event.json +48 -0
  38. data/spec/fixtures/fork_event.json +139 -0
  39. data/spec/fixtures/gist_event.json +27 -0
  40. data/spec/fixtures/gollum_event.json +30 -0
  41. data/spec/fixtures/issue_comment_event.json +97 -0
  42. data/spec/fixtures/issues_event.json +70 -0
  43. data/spec/fixtures/member_event.json +39 -0
  44. data/spec/fixtures/public_event.json +16 -0
  45. data/spec/fixtures/pull_request_event.json +400 -0
  46. data/spec/fixtures/pull_request_review_comment_event.json +73 -0
  47. data/spec/fixtures/push_event.json +35 -0
  48. data/spec/fixtures/team_add_event.json +51 -0
  49. data/spec/fixtures/watch_event.json +23 -0
  50. data/spec/helper.rb +79 -0
  51. data/spec/octospy/extensions/string_spec.rb +84 -0
  52. data/spec/octospy/parser/download_spec.rb +9 -0
  53. data/spec/octospy/parser/gist_spec.rb +17 -0
  54. data/spec/octospy/parser/issue_spec.rb +33 -0
  55. data/spec/octospy/parser/organization_spec.rb +33 -0
  56. data/spec/octospy/parser/pull_request_spec.rb +33 -0
  57. data/spec/octospy/parser/repository_spec.rb +101 -0
  58. data/spec/octospy/parser/user_spec.rb +44 -0
  59. data/spec/octospy/parser/wiki_spec.rb +17 -0
  60. data/spec/octospy/parser_spec.rb +63 -0
  61. data/spec/octospy/shortener_spec.rb +46 -0
  62. data/spec/support/shared_context.rb +60 -0
  63. metadata +345 -0
data/spec/helper.rb ADDED
@@ -0,0 +1,79 @@
1
+ # coding: utf-8
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ require 'octospy'
6
+ require 'rspec'
7
+ require 'json'
8
+ require 'hashie'
9
+ require 'awesome_print'
10
+ require 'webmock/rspec'
11
+ require 'vcr'
12
+
13
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ Coveralls::SimpleCov::Formatter
16
+ ]
17
+ SimpleCov.start
18
+
19
+ WebMock.disable_net_connect!(allow: 'coveralls.io')
20
+ RSpec.configure { |c| c.include WebMock::API }
21
+
22
+ VCR.configure do |c|
23
+ c.cassette_library_dir = 'spec/cassettes'
24
+ c.hook_into :webmock
25
+ end
26
+
27
+ class String
28
+ def strip_heredoc
29
+ indent = scan(/^[ \t]*(?=\S)/).min.size || 0
30
+ gsub(/^[ \t]{#{indent}}/, '')
31
+ end
32
+
33
+ def no_lf
34
+ gsub(/\n|\r\n/, ' ')
35
+ end
36
+
37
+ def pretty_heredoc
38
+ strip_heredoc.no_lf.strip
39
+ end
40
+
41
+ def escaping
42
+ gsub(/https?:\/\//, '').gsub(/\/|\./, '_')
43
+ end
44
+ end
45
+
46
+ def fixture_path
47
+ File.expand_path('../fixtures', __FILE__)
48
+ end
49
+
50
+ def fixture(file)
51
+ File.read(fixture_path + '/' + file)
52
+ end
53
+
54
+ def decode(file)
55
+ JSON.parse(fixture file)
56
+ end
57
+
58
+ def json_response(file)
59
+ {
60
+ body: fixture(file),
61
+ headers: { content_type: 'application/json; charset=utf-8' }
62
+ }
63
+ end
64
+
65
+ def method_missing(method, *args, &block)
66
+ if method =~ /^a_(get|post|put|delete)$/
67
+ a_request(Regexp.last_match[1].to_sym, *args, &block)
68
+ elsif method =~ /^stub_(get|post|put|delete|head|patch)$/
69
+ stub_request(Regexp.last_match[1].to_sym, *args, &block)
70
+ else
71
+ super
72
+ end
73
+ end
74
+
75
+ def support_path
76
+ File.expand_path('../support', __FILE__)
77
+ end
78
+
79
+ Dir["#{support_path}/**/*.rb"].each { |f| require f }
@@ -0,0 +1,84 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Extensions::String do
4
+ describe '#underscore' do
5
+ it { expect('FooBar'.underscore).to eq 'foo_bar' }
6
+ it { expect('fooBar'.underscore).to eq 'foo_bar' }
7
+ it { expect('fooBaR'.underscore).to eq 'foo_ba_r' }
8
+ it { expect('foo-bar'.underscore).to eq 'foo_bar' }
9
+ it { expect('foo/bar'.underscore).to eq 'foo/bar' }
10
+ it { expect('Foo::Bar'.underscore).to eq 'foo/bar' }
11
+ end
12
+
13
+ describe '#split_by_linefeed_except_blankline' do
14
+ subject { sentence.split_by_linefeed_except_blankline }
15
+
16
+ context 'when include line feed' do
17
+ let(:sentence) {
18
+ <<-RUBY.strip_heredoc
19
+ That lucid breeze in Ihatov,
20
+ Blue sky that has coolness at the bottom even in summer,
21
+ Morio which has been decorated with beautiful forest,
22
+ grass wave shines garishly in suburb.
23
+ RUBY
24
+ }
25
+
26
+ it { expect(subject).to be_instance_of Array }
27
+ it { expect(subject).to have(4).items }
28
+ it { expect(subject[1]).to include 'Blue sky' }
29
+ end
30
+
31
+ context 'when not include line feed' do
32
+ let(:sentence) { 'hi, hello world.' }
33
+
34
+ it { expect(subject).to be_instance_of Array }
35
+ it { expect(subject).to have(1).items }
36
+ end
37
+
38
+ it 'have alias_method' do
39
+ expect(''.respond_to? :split_lfbl).to be_true
40
+ end
41
+ end
42
+
43
+ describe '#colorize_for_irc' do
44
+ let(:word) { 'hello world' }
45
+
46
+ it 'call StringIrc#new' do
47
+ expect(StringIrc).to receive(:new).with(word).once.and_call_original
48
+ expect(word.colorize_for_irc).to be_instance_of StringIrc
49
+ end
50
+ end
51
+
52
+ describe '#shorten_url' do
53
+ context 'when it is in the url of github' do
54
+ let(:url) { 'https://github.com/linyows/octospy' }
55
+ let(:result) { 'http://git.io/aaaaa' }
56
+
57
+ it 'call Octospy::Shortener.shorten_by_github' do
58
+ expect(Octospy::Shortener).to receive(:shorten_by_github).and_return result
59
+ expect(url.shorten_url).to eq result
60
+ end
61
+ end
62
+
63
+ context 'when it is not in the url of github' do
64
+ let(:url) { 'http://www.google.com/search?q=octospy' }
65
+ let(:result) { 'http://goo.gl/aaaaa' }
66
+
67
+ it 'call Octospy::Shortener.shorten_by_google' do
68
+ expect(Octospy::Shortener).to receive(:shorten_by_google).and_return result
69
+ expect(url.shorten_url).to eq result
70
+ end
71
+ end
72
+
73
+ context 'when it is not in the url' do
74
+ let(:url) { 'hello world' }
75
+ let(:result) { url }
76
+
77
+ it 'not call Octospy::Shortener' do
78
+ expect(Octospy::Shortener).to_not receive(:shorten_by_github)
79
+ expect(Octospy::Shortener).to_not receive(:shorten_by_google)
80
+ expect(url.shorten_url).to eq result
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,9 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_download_event' do
7
+ it {}
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_gist_event' do
7
+ let(:event_name) { 'gist_event' }
8
+ before { parser.instance_variable_set(:@event, event) }
9
+
10
+ subject { parser.parse_gist_event }
11
+
12
+ it { expect(subject[:status]).to eq 'created gist' }
13
+ it { expect(subject[:title]).to eq 'testing activegist' }
14
+ it { expect(subject[:body]).to be_nil }
15
+ it { expect(subject[:link]).to eq 'https://gist.github.com/5993603' }
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_issues_event' do
7
+ let(:event_name) { 'issues_event' }
8
+ before { parser.instance_variable_set(:@event, event) }
9
+
10
+ subject { parser.parse_issues_event }
11
+
12
+ it { expect(subject[:status]).to eq 'opened issue #430' }
13
+ it { expect(subject[:title]).to eq 'mismatching hashes for css' }
14
+ it { expect(subject[:body]).to be_an_instance_of Array }
15
+ it { expect(subject[:body]).to include 'Server: nginx/1.4.1' }
16
+ it { expect(subject[:body]).to have(40).items }
17
+ it { expect(subject[:link]).to eq 'https://github.com/pagespeed/ngx_pagespeed/issues/430' }
18
+ end
19
+
20
+ describe '#parse_issue_comment_event' do
21
+ let(:event_name) { 'issue_comment_event' }
22
+ before { parser.instance_variable_set(:@event, event) }
23
+
24
+ subject { parser.parse_issue_comment_event }
25
+
26
+ it { expect(subject[:status]).to eq 'commented on issue #582' }
27
+ it { expect(subject[:title]).to eq 'Remove `engines` from package.json.' }
28
+ it { expect(subject[:body]).to be_an_instance_of Array }
29
+ it { expect(subject[:body][0]).to include 'anything?' }
30
+ it { expect(subject[:body]).to have(1).items }
31
+ it { expect(subject[:link]).to eq 'https://github.com/bower/bower/issues/582#issuecomment-20416296' }
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_team_add_event' do
7
+ let(:event_name) { 'team_add_event' }
8
+ before { parser.instance_variable_set(:@event, event) }
9
+
10
+ subject { parser.parse_team_add_event }
11
+
12
+ it { expect(subject[:status]).to eq 'add team' }
13
+ it { expect(subject[:title]).to eq 'dev' }
14
+ it { expect(subject[:body]).to be_nil }
15
+ it { expect(subject[:link]).to be_nil }
16
+ end
17
+
18
+ describe '#parse_member_event' do
19
+ let(:event_name) { 'member_event' }
20
+
21
+ before do
22
+ client.stub(:web_endpoint).and_return Octokit.web_endpoint
23
+ parser.instance_variable_set(:@event, event)
24
+ end
25
+
26
+ subject { parser.parse_member_event }
27
+
28
+ it { expect(subject[:status]).to eq 'added member' }
29
+ it { expect(subject[:title]).to eq 'jamiesarahg' }
30
+ it { expect(subject[:body]).to be_nil }
31
+ it { expect(subject[:link]).to eq 'https://github.com//jamiesarahg' }
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_pull_request_event' do
7
+ let(:event_name) { 'pull_request_event' }
8
+ before { parser.instance_variable_set(:@event, event) }
9
+
10
+ subject { parser.parse_pull_request_event }
11
+
12
+ it { expect(subject[:status]).to eq 'closed pull request #11363' }
13
+ it { expect(subject[:title]).to eq 'Fix 2 grammatical errors/typos in Active Record Basics guide.' }
14
+ it { expect(subject[:body]).to eq [] }
15
+ it { expect(subject[:link]).to eq 'https://github.com/rails/rails/pull/11363' }
16
+ end
17
+
18
+ describe '#parse_pull_request_review_comment_event' do
19
+ let(:pull) { double(Octokit::Client, title: 'Mocking title') }
20
+ let(:client) { double(Octokit::Client, pull: pull) }
21
+ let(:event_name) { 'pull_request_review_comment_event' }
22
+ before { parser.instance_variable_set(:@event, event) }
23
+
24
+ subject { parser.parse_pull_request_review_comment_event }
25
+
26
+ it { expect(subject[:status]).to eq 'commented on pull request' }
27
+ it { expect(subject[:title]).to eq 'Mocking title: packages/ember-handlebars/lib/helpers/collection.js' }
28
+ it { expect(subject[:body]).to be_an_instance_of Array }
29
+ it { expect(subject[:body][0]).to include 'Of course.' }
30
+ it { expect(subject[:body]).to have(1).items }
31
+ it { expect(subject[:link]).to eq 'https://github.com/emberjs/ember.js/pull/2930#discussion_r5064430' }
32
+ end
33
+ end
@@ -0,0 +1,101 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_push_event' do
7
+ let(:shorten_url) { 'http://git.io/Qq_ufw' }
8
+ let(:client) {
9
+ client = double(Octokit::Client)
10
+ client.stub_chain(:commit, :author, :login).and_return('mockingname')
11
+ client.stub(:web_endpoint).and_return(Octokit.web_endpoint)
12
+ String.any_instance.stub(:shorten).and_return shorten_url
13
+ client
14
+ }
15
+ let(:event_name) { 'push_event' }
16
+
17
+ before { parser.instance_variable_set(:@event, event) }
18
+
19
+ subject { parser.parse_push_event }
20
+
21
+ it { expect(subject[:status]).to eq 'pushed to master' }
22
+ it { expect(subject[:title]).to be_nil }
23
+ it { expect(subject[:body]).to be_an_instance_of Array }
24
+ it {
25
+ expect(subject[:body][0]).to eq <<-BODY.pretty_heredoc
26
+ \u000315mockingname\u000F:
27
+ update send and connect - \u000302#{shorten_url}\u000F
28
+ BODY
29
+ }
30
+ it { expect(subject[:body]).to have(2).items }
31
+ it { expect(subject[:link]).to eq 'https://github.com//visionmedia/express' }
32
+ end
33
+
34
+ describe '#parse_create_event' do
35
+ let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
36
+ let(:event_name) { 'create_event' }
37
+ before { parser.instance_variable_set(:@event, event) }
38
+
39
+ subject { parser.parse_create_event }
40
+
41
+ it { expect(subject[:status]).to eq 'created tag:3.3.3' }
42
+ it {
43
+ expect(subject[:title]).to eq <<-TITLE.pretty_heredoc
44
+ Sinatra inspired web development framework for node.js -- insanely fast,
45
+ flexible, and simple
46
+ TITLE
47
+ }
48
+ it { expect(subject[:body]).to be_nil }
49
+ it { expect(subject[:link]).to eq 'https://github.com//visionmedia/express' }
50
+ end
51
+
52
+ describe '#parse_commit_comment_event' do
53
+ let(:event_name) { 'commit_comment_event' }
54
+ before { parser.instance_variable_set(:@event, event) }
55
+
56
+ subject { parser.parse_commit_comment_event }
57
+
58
+ it { expect(subject[:status]).to eq 'commented on commit' }
59
+ it { expect(subject[:title]).to eq '' }
60
+ it { expect(subject[:body]).to be_an_instance_of Array }
61
+ it { expect(subject[:body][0]).to include 'AFAIK' }
62
+ it { expect(subject[:body]).to have(1).items }
63
+ it { expect(subject[:link]).to eq 'https://github.com/boxen/our-boxen/commit/08009e9b0718869d269d9b1c48383e6e145950db#commitcomment-3583654' }
64
+ end
65
+
66
+ describe '#parse_delete_event' do
67
+ let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
68
+ let(:event_name) { 'delete_event' }
69
+ before { parser.instance_variable_set(:@event, event) }
70
+
71
+ subject { parser.parse_delete_event }
72
+
73
+ it { expect(subject[:status]).to eq 'deleted branch:jefftk-fix-beacon' }
74
+ it { expect(subject[:title]).to be_nil }
75
+ it { expect(subject[:body]).to be_nil }
76
+ it { expect(subject[:link]).to eq 'https://github.com//pagespeed/ngx_pagespeed' }
77
+ end
78
+
79
+ describe '#parse_fork_event' do
80
+ end
81
+
82
+ describe '#parse_fork_apply_event' do
83
+ it { expect(parser.parse_fork_apply_event).to eq({}) }
84
+ end
85
+
86
+ describe '#parse_public_event' do
87
+ let(:event_name) { 'public_event' }
88
+
89
+ before do
90
+ client.stub(:web_endpoint).and_return Octokit.web_endpoint
91
+ parser.instance_variable_set(:@event, event)
92
+ end
93
+
94
+ subject { parser.parse_public_event }
95
+
96
+ it { expect(subject[:status]).to eq 'published JustinBeaudry/brudniakbook' }
97
+ it { expect(subject[:title]).to be_nil }
98
+ it { expect(subject[:body]).to be_nil }
99
+ it { expect(subject[:link]).to eq 'https://github.com//JustinBeaudry/brudniakbook' }
100
+ end
101
+ end
@@ -0,0 +1,44 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_watch_event' do
7
+ let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
8
+ let(:event_name) { 'watch_event' }
9
+ before { parser.instance_variable_set(:@event, event) }
10
+
11
+ subject { parser.parse_watch_event }
12
+
13
+ it { expect(subject[:status]).to eq 'started repository' }
14
+ it { expect(subject[:title]).to eq 'intridea/hashie' }
15
+ it { expect(subject[:body]).to be_nil }
16
+ it { expect(subject[:link]).to eq 'https://github.com//intridea/hashie' }
17
+ it { expect(subject[:repository]).to be_nil }
18
+ end
19
+
20
+ describe '#parse_follow_event' do
21
+ let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
22
+ let(:event_name) { 'follow_event' }
23
+ before { parser.instance_variable_set(:@event, event) }
24
+
25
+ subject { parser.parse_follow_event }
26
+
27
+ it { expect(subject[:status]).to eq 'followed' }
28
+ it { expect(subject[:title]).to eq 'Watson1978 (Watson)' }
29
+ it {
30
+ expect(subject[:body]).to eq <<-BODY.pretty_heredoc
31
+ \u000315repos\u000F: 66,
32
+ \u000315followers\u000F: 101,
33
+ \u000315following\u000F: 15,
34
+ \u000315location\u000F: Japan,
35
+ \u000315company\u000F: -,
36
+ \u000315bio\u000F: -,
37
+ \u000315blog\u000F: http://watson1978.github.io/
38
+ BODY
39
+ }
40
+ it { expect(subject[:link]).to eq 'https://github.com//Watson1978' }
41
+ it { expect(subject[:repository]).to be_nil }
42
+ it { expect(subject[:notice]).to be_true }
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#parse_gollum_event' do
7
+ let(:event_name) { 'gollum_event' }
8
+ before { parser.instance_variable_set(:@event, event) }
9
+
10
+ subject { parser.parse_gollum_event }
11
+
12
+ it { expect(subject[:status]).to eq 'edited the component/component wiki' }
13
+ it { expect(subject[:title]).to eq 'Components' }
14
+ it { expect(subject[:body]).to be_nil }
15
+ it { expect(subject[:link]).to eq 'https://github.com/component/component/wiki/Components/_compare/3df147%5E...3df147' }
16
+ end
17
+ end
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Parser do
4
+ include_context :parser_params
5
+
6
+ describe '#initialize' do
7
+ it { expect(parser).to be_an_instance_of Octospy::Parser }
8
+ end
9
+
10
+ describe '#default_params' do
11
+ it { expect(parser.default_params).to eq default_params }
12
+ end
13
+
14
+ describe '#parse' do
15
+ it {
16
+ expect(parser).to receive(:parsing_method).once.and_return(parsing_method)
17
+ expect(parser).to receive(parsing_method).once.and_return(parsed_params)
18
+ expect(parser).to receive(:build).once.with(merged_params).and_return(built_params)
19
+ expect(parser.parse event).to eq built_params
20
+ }
21
+ end
22
+
23
+ describe '#build' do
24
+ it {
25
+ expect_any_instance_of(String).to receive(:shorten).once.and_return('http://git.io/A0ARbg')
26
+ expect(parser.build merged_params).to eq built_params
27
+ }
28
+ end
29
+
30
+ describe '#parsing_method' do
31
+ let(:event) { double(Octokit::Client, type: 'FooBarBaz') }
32
+ before { parser.instance_variable_set(:@event, event) }
33
+ it { expect(parser.parsing_method).to eq :parse_foo_bar_baz }
34
+ end
35
+
36
+ describe '#behavior_color' do
37
+ {
38
+ pink: 'created',
39
+ yellow: 'commented',
40
+ lime: 'pushed',
41
+ orange: 'forked',
42
+ brown: 'closed',
43
+ red: 'deleted',
44
+ green: 'edited',
45
+ blue: 'published',
46
+ rainbow: 'started',
47
+ seven_eleven: 'followed',
48
+ aqua: 'foobar'
49
+ }.each { |color, word|
50
+ it { expect(parser.behavior_color word).to eq color }
51
+ }
52
+ end
53
+
54
+ describe '#colorize_to' do
55
+ let(:sentence) { 'created issue' }
56
+
57
+ it {
58
+ expect_any_instance_of(StringIrc).to receive(:pink).
59
+ once.with(no_args).and_call_original
60
+ expect(parser.colorize_to sentence).to eq "\u000313#{sentence}\u000F"
61
+ }
62
+ end
63
+ end
@@ -0,0 +1,46 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Shortener do
4
+ let(:url) { 'https://github.com/linyows/octospy' }
5
+
6
+ describe '.shorten_by_github' do
7
+ subject {
8
+ VCR.use_cassette "git.io/#{url.escaping}" do
9
+ described_class.shorten_by_github url
10
+ end
11
+ }
12
+
13
+ it { expect(subject).to be_an_instance_of String }
14
+ it { expect(subject).to eq 'http://git.io/Pd8gXg' }
15
+
16
+ context 'when it is not in the url of github' do
17
+ let(:url) { 'https://www.google.co.jp/search?q=octospy' }
18
+ it { expect(subject).to eq url }
19
+ end
20
+
21
+ context 'when raise error' do
22
+ it 'return url of argument' do
23
+ expect(Faraday).to receive(:new).and_raise Faraday::Error
24
+ expect(described_class.shorten_by_github url).to eq url
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '.shorten_by_google' do
30
+ subject {
31
+ VCR.use_cassette "googleapis.com/urlshortener/#{url.escaping}" do
32
+ described_class.shorten_by_google url
33
+ end
34
+ }
35
+
36
+ it { expect(subject).to be_an_instance_of String }
37
+ it { expect(subject).to eq 'http://goo.gl/8vrLj' }
38
+
39
+ context 'when raise error' do
40
+ it 'return url of argument' do
41
+ expect(Faraday).to receive(:new).and_raise Faraday::Error
42
+ expect(described_class.shorten_by_google url).to eq url
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,60 @@
1
+ shared_context :parser_params do
2
+ let(:client) { double Octokit::Client }
3
+ let(:parser) { described_class.new client }
4
+ let(:event_name) { 'issue_comment_event' }
5
+ let(:parsing_method) { :"parse_#{event_name}" }
6
+ let(:file) { "#{event_name}.json" }
7
+ let(:event) { Hashie::Mash.new.deep_merge(decode file) }
8
+
9
+ let(:default_params) do
10
+ {
11
+ notice_body: false,
12
+ none_repository: false,
13
+ nick: '',
14
+ repository: '',
15
+ status: '',
16
+ link: '',
17
+ title: '',
18
+ body: []
19
+ }
20
+ end
21
+
22
+ let(:parsed_params) do
23
+ {
24
+ status: 'commented on issue #582',
25
+ title: 'Remove `engines` from package.json.',
26
+ body: [
27
+ <<-BODY.pretty_heredoc
28
+ Has is ever done anything? It still has a purpose though;
29
+ To warn users that they're using antdated version.
30
+ BODY
31
+ ],
32
+ link: 'https://github.com/bower/bower/issues/582#issuecomment-20416296'
33
+ }
34
+ end
35
+
36
+ let(:merged_params) do
37
+ default_params.merge(parsed_params).merge(
38
+ nick: 'sindresorhus',
39
+ repository: 'bower/bower'
40
+ )
41
+ end
42
+
43
+ let(:built_params) do
44
+ [
45
+ {
46
+ nick: merged_params[:nick],
47
+ type: :notice,
48
+ message: <<-MSG.pretty_heredoc
49
+ (bower/bower) \u0002sindresorhus\u000F \u000308commented on issue #582\u000F
50
+ Remove `engines` from package.json. - \u000302http://git.io/A0ARbg\u000F
51
+ MSG
52
+ },
53
+ {
54
+ nick: merged_params[:nick],
55
+ type: :private,
56
+ message: parsed_params[:body]
57
+ }
58
+ ]
59
+ end
60
+ end