codeclimate-services 1.6.1 → 1.7.0

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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.rubocop.yml +1 -0
  4. data/Gemfile +1 -2
  5. data/Rakefile +4 -7
  6. data/base_rubocop.yml +152 -0
  7. data/bin/bundler +5 -5
  8. data/bin/coderay +5 -5
  9. data/bin/nokogiri +5 -5
  10. data/bin/pry +5 -5
  11. data/bin/rake +5 -5
  12. data/codeclimate-services.gemspec +15 -15
  13. data/config/load.rb +2 -2
  14. data/lib/cc/formatters/linked_formatter.rb +2 -2
  15. data/lib/cc/formatters/snapshot_formatter.rb +10 -10
  16. data/lib/cc/formatters/ticket_formatter.rb +0 -2
  17. data/lib/cc/helpers/quality_helper.rb +2 -2
  18. data/lib/cc/helpers/vulnerability_helper.rb +0 -2
  19. data/lib/cc/presenters/pull_requests_presenter.rb +1 -5
  20. data/lib/cc/pull_requests.rb +7 -3
  21. data/lib/cc/service.rb +9 -10
  22. data/lib/cc/service/formatter.rb +3 -3
  23. data/lib/cc/service/helper.rb +2 -3
  24. data/lib/cc/service/http.rb +9 -9
  25. data/lib/cc/service/invocation.rb +6 -6
  26. data/lib/cc/service/invocation/with_error_handling.rb +9 -8
  27. data/lib/cc/service/invocation/with_metrics.rb +4 -4
  28. data/lib/cc/service/invocation/with_return_values.rb +0 -1
  29. data/lib/cc/service/response_check.rb +4 -5
  30. data/lib/cc/services.rb +2 -2
  31. data/lib/cc/services/asana.rb +8 -9
  32. data/lib/cc/services/campfire.rb +2 -3
  33. data/lib/cc/services/flowdock.rb +5 -5
  34. data/lib/cc/services/github_issues.rb +6 -7
  35. data/lib/cc/services/github_pull_requests.rb +42 -5
  36. data/lib/cc/services/gitlab_merge_requests.rb +6 -2
  37. data/lib/cc/services/hipchat.rb +3 -4
  38. data/lib/cc/services/jira.rb +8 -9
  39. data/lib/cc/services/lighthouse.rb +4 -5
  40. data/lib/cc/services/pivotal_tracker.rb +6 -7
  41. data/lib/cc/services/slack.rb +8 -8
  42. data/lib/cc/services/stash_pull_requests.rb +2 -2
  43. data/lib/cc/services/version.rb +1 -1
  44. data/pull_request_test.rb +11 -10
  45. data/service_test.rb +5 -5
  46. data/spec/axiom/types/password_spec.rb +14 -0
  47. data/spec/cc/formatters/snapshot_formatter_spec.rb +44 -0
  48. data/spec/cc/presenters/pull_requests_presenter_spec.rb +45 -0
  49. data/{test/asana_test.rb → spec/cc/service/asana_spec.rb} +27 -29
  50. data/{test/campfire_test.rb → spec/cc/service/campfire_spec.rb} +40 -44
  51. data/{test/flowdock_test.rb → spec/cc/service/flowdock_spec.rb} +46 -48
  52. data/{test/github_issues_test.rb → spec/cc/service/github_issues_spec.rb} +33 -35
  53. data/spec/cc/service/github_pull_requests_spec.rb +223 -0
  54. data/{test/gitlab_merge_requests_test.rb → spec/cc/service/gitlab_merge_requests_spec.rb} +30 -35
  55. data/{test/hipchat_test.rb → spec/cc/service/hipchat_spec.rb} +38 -40
  56. data/spec/cc/service/invocation/error_handling_spec.rb +49 -0
  57. data/spec/cc/service/invocation/return_values_spec.rb +19 -0
  58. data/spec/cc/service/invocation/with_metrics_spec.rb +18 -0
  59. data/{test/invocation_test.rb → spec/cc/service/invocation_spec.rb} +31 -34
  60. data/{test/jira_test.rb → spec/cc/service/jira_spec.rb} +25 -27
  61. data/{test/lighthouse_test.rb → spec/cc/service/lighthouse_spec.rb} +23 -26
  62. data/spec/cc/service/pivotal_tracker_spec.rb +70 -0
  63. data/{test/slack_test.rb → spec/cc/service/slack_spec.rb} +66 -77
  64. data/spec/cc/service/stash_pull_requests_spec.rb +132 -0
  65. data/spec/cc/service_spec.rb +78 -0
  66. data/{test → spec}/fixtures.rb +3 -4
  67. data/spec/spec_helper.rb +37 -0
  68. data/{test → spec}/support/fake_logger.rb +0 -0
  69. data/spec/support/service_context.rb +42 -0
  70. metadata +57 -52
  71. data/test/axiom/types/password_test.rb +0 -22
  72. data/test/formatters/snapshot_formatter_test.rb +0 -47
  73. data/test/github_pull_requests_test.rb +0 -217
  74. data/test/helper.rb +0 -58
  75. data/test/invocation_error_handling_test.rb +0 -51
  76. data/test/invocation_return_values_test.rb +0 -21
  77. data/test/pivotal_tracker_test.rb +0 -73
  78. data/test/presenters/pull_requests_presenter_test.rb +0 -70
  79. data/test/service_test.rb +0 -84
  80. data/test/stash_pull_requests_test.rb +0 -146
  81. data/test/with_metrics_test.rb +0 -19
@@ -1,70 +1,68 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class TestJira < CC::Service::TestCase
4
- def test_successful_receive
1
+ describe CC::Service::Jira, type: :service do
2
+ it "successful receive" do
5
3
  response = assert_jira_receives(
6
4
  event(:quality, to: "D", from: "C"),
7
5
  "Refactor User from a D on Code Climate",
8
- "https://codeclimate.com/repos/1/feed"
6
+ "https://codeclimate.com/repos/1/feed",
9
7
  )
10
- assert_equal "10000", response[:id]
8
+ expect(response[:id]).to eq("10000")
11
9
  end
12
10
 
13
- def test_quality
11
+ it "quality" do
14
12
  assert_jira_receives(
15
13
  event(:quality, to: "D", from: "C"),
16
14
  "Refactor User from a D on Code Climate",
17
- "https://codeclimate.com/repos/1/feed"
15
+ "https://codeclimate.com/repos/1/feed",
18
16
  )
19
17
  end
20
18
 
21
- def test_vulnerability
19
+ it "vulnerability" do
22
20
  assert_jira_receives(
23
21
  event(:vulnerability, vulnerabilities: [{
24
- "warning_type" => "critical",
25
- "location" => "app/user.rb line 120"
26
- }]),
22
+ "warning_type" => "critical",
23
+ "location" => "app/user.rb line 120",
24
+ }]),
27
25
  "New critical issue found in app/user.rb line 120",
28
- "A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
26
+ "A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed",
29
27
  )
30
28
  end
31
29
 
32
- def test_issue
30
+ it "issue" do
33
31
  payload = {
34
32
  issue: {
35
33
  "check_name" => "Style/LongLine",
36
- "description" => "Line is too long [1000/80]"
34
+ "description" => "Line is too long [1000/80]",
37
35
  },
38
36
  constant_name: "foo.rb",
39
- details_url: "http://example.com/repos/id/foo.rb#issue_123"
37
+ details_url: "http://example.com/repos/id/foo.rb#issue_123",
40
38
  }
41
39
 
42
40
  assert_jira_receives(
43
41
  event(:issue, payload),
44
42
  "Fix \"Style/LongLine\" issue in foo.rb",
45
- "Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123"
43
+ "Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
46
44
  )
47
45
  end
48
46
 
49
- def test_receive_test
50
- @stubs.post '/rest/api/2/issue' do |env|
47
+ it "receive test" do
48
+ http_stubs.post "/rest/api/2/issue" do |_env|
51
49
  [200, {}, '{"id": 12345, "key": "CC-123", "self": "http://foo.bar"}']
52
50
  end
53
51
 
54
52
  response = receive_event(name: "test")
55
53
 
56
- assert_equal "Ticket <a href='https://foo.com/browse/CC-123'>12345</a> created.", response[:message]
54
+ expect(response[:message]).to eq("Ticket <a href='https://foo.com/browse/CC-123'>12345</a> created.")
57
55
  end
58
56
 
59
57
  private
60
58
 
61
59
  def assert_jira_receives(event_data, title, ticket_body)
62
- @stubs.post '/rest/api/2/issue' do |env|
60
+ http_stubs.post "/rest/api/2/issue" do |env|
63
61
  body = JSON.parse(env[:body])
64
- assert_equal "Basic Zm9vOmJhcg==", env[:request_headers]["Authorization"]
65
- assert_equal title, body["fields"]["summary"]
66
- assert_equal ticket_body, body["fields"]["description"]
67
- assert_equal "Task", body["fields"]["issuetype"]["name"]
62
+ expect(env[:request_headers]["Authorization"]).to eq("Basic Zm9vOmJhcg==")
63
+ expect(body["fields"]["summary"]).to eq(title)
64
+ expect(body["fields"]["description"]).to eq(ticket_body)
65
+ expect(body["fields"]["issuetype"]["name"]).to eq("Task")
68
66
  [200, {}, '{"id":"10000"}']
69
67
  end
70
68
 
@@ -72,10 +70,10 @@ class TestJira < CC::Service::TestCase
72
70
  end
73
71
 
74
72
  def receive_event(event_data = nil)
75
- receive(
73
+ service_receive(
76
74
  CC::Service::Jira,
77
75
  { domain: "foo.com", username: "foo", password: "bar", project_id: "100" },
78
- event_data || event(:quality, from: "C", to: "D")
76
+ event_data || event(:quality, from: "C", to: "D"),
79
77
  )
80
78
  end
81
79
  end
@@ -1,63 +1,60 @@
1
- require File.expand_path('../helper', __FILE__)
2
-
3
- class TestLighthouse < CC::Service::TestCase
4
- def test_quality
1
+ describe CC::Service::Lighthouse, type: :service do
2
+ it "quality" do
5
3
  response = assert_lighthouse_receives(
6
4
  event(:quality, to: "D", from: "C"),
7
5
  "Refactor User from a D on Code Climate",
8
- "https://codeclimate.com/repos/1/feed"
6
+ "https://codeclimate.com/repos/1/feed",
9
7
  )
10
- assert_equal "123", response[:id]
11
- assert_equal "http://lighthouse.com/projects/123/tickets/123.json",
12
- response[:url]
8
+ expect(response[:id]).to eq("123")
9
+ expect("http://lighthouse.com/projects/123/tickets/123.json").to eq(response[:url])
13
10
  end
14
11
 
15
- def test_vulnerability
12
+ it "vulnerability" do
16
13
  assert_lighthouse_receives(
17
14
  event(:vulnerability, vulnerabilities: [{
18
- "warning_type" => "critical",
19
- "location" => "app/user.rb line 120"
20
- }]),
15
+ "warning_type" => "critical",
16
+ "location" => "app/user.rb line 120",
17
+ }]),
21
18
  "New critical issue found in app/user.rb line 120",
22
- "A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed"
19
+ "A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed",
23
20
  )
24
21
  end
25
22
 
26
- def test_issue
23
+ it "issue" do
27
24
  payload = {
28
25
  issue: {
29
26
  "check_name" => "Style/LongLine",
30
- "description" => "Line is too long [1000/80]"
27
+ "description" => "Line is too long [1000/80]",
31
28
  },
32
29
  constant_name: "foo.rb",
33
- details_url: "http://example.com/repos/id/foo.rb#issue_123"
30
+ details_url: "http://example.com/repos/id/foo.rb#issue_123",
34
31
  }
35
32
 
36
33
  assert_lighthouse_receives(
37
34
  event(:issue, payload),
38
35
  "Fix \"Style/LongLine\" issue in foo.rb",
39
- "Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123"
36
+ "Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
40
37
  )
41
38
  end
42
39
 
43
- def test_receive_test
44
- @stubs.post 'projects/123/tickets.json' do |env|
40
+ it "receive test" do
41
+ http_stubs.post "projects/123/tickets.json" do |_env|
45
42
  [200, {}, '{"ticket":{"number": "123", "url":"http://foo.bar"}}']
46
43
  end
47
44
 
48
45
  response = receive_event(name: "test")
49
46
 
50
- assert_equal "Ticket <a href='http://foo.bar'>123</a> created.", response[:message]
47
+ expect(response[:message]).to eq("Ticket <a href='http://foo.bar'>123</a> created.")
51
48
  end
52
49
 
53
50
  private
54
51
 
55
52
  def assert_lighthouse_receives(event_data, title, ticket_body)
56
- @stubs.post 'projects/123/tickets.json' do |env|
53
+ http_stubs.post "projects/123/tickets.json" do |env|
57
54
  body = JSON.parse(env[:body])
58
- assert_equal "token", env[:request_headers]["X-LighthouseToken"]
59
- assert_equal title, body["ticket"]["title"]
60
- assert_equal ticket_body, body["ticket"]["body"]
55
+ expect(env[:request_headers]["X-LighthouseToken"]).to eq("token")
56
+ expect(body["ticket"]["title"]).to eq(title)
57
+ expect(body["ticket"]["body"]).to eq(ticket_body)
61
58
  [200, {}, '{"ticket":{"number": "123", "url":"http://lighthouse.com/projects/123/tickets/123.json"}}']
62
59
  end
63
60
 
@@ -65,10 +62,10 @@ class TestLighthouse < CC::Service::TestCase
65
62
  end
66
63
 
67
64
  def receive_event(event_data = nil)
68
- receive(
65
+ service_receive(
69
66
  CC::Service::Lighthouse,
70
67
  { subdomain: "foo", api_token: "token", project_id: "123" },
71
- event_data || event(:quality, from: "C", to: "D")
68
+ event_data || event(:quality, from: "C", to: "D"),
72
69
  )
73
70
  end
74
71
  end
@@ -0,0 +1,70 @@
1
+ describe CC::Service::PivotalTracker, type: :service do
2
+ it "quality" do
3
+ response = assert_pivotal_receives(
4
+ event(:quality, to: "D", from: "C"),
5
+ "Refactor User from a D on Code Climate",
6
+ "https://codeclimate.com/repos/1/feed",
7
+ )
8
+ expect(response[:id]).to eq("123")
9
+ expect("http://pivotaltracker.com/n/projects/123/stories/123").to eq(response[:url])
10
+ end
11
+
12
+ it "vulnerability" do
13
+ assert_pivotal_receives(
14
+ event(:vulnerability, vulnerabilities: [{
15
+ "warning_type" => "critical",
16
+ "location" => "app/user.rb line 120",
17
+ }]),
18
+ "New critical issue found in app/user.rb line 120",
19
+ "A critical vulnerability was found by Code Climate in app/user.rb line 120.\n\nhttps://codeclimate.com/repos/1/feed",
20
+ )
21
+ end
22
+
23
+ it "issue" do
24
+ payload = {
25
+ issue: {
26
+ "check_name" => "Style/LongLine",
27
+ "description" => "Line is too long [1000/80]",
28
+ },
29
+ constant_name: "foo.rb",
30
+ details_url: "http://example.com/repos/id/foo.rb#issue_123",
31
+ }
32
+
33
+ assert_pivotal_receives(
34
+ event(:issue, payload),
35
+ "Fix \"Style/LongLine\" issue in foo.rb",
36
+ "Line is too long [1000/80]\n\nhttp://example.com/repos/id/foo.rb#issue_123",
37
+ )
38
+ end
39
+
40
+ it "receive test" do
41
+ http_stubs.post "services/v3/projects/123/stories" do |_env|
42
+ [200, {}, "<story><id>123</id><url>http://foo.bar</url></story>"]
43
+ end
44
+
45
+ response = receive_event(name: "test")
46
+
47
+ expect(response[:message]).to eq("Ticket <a href='http://foo.bar'>123</a> created.")
48
+ end
49
+
50
+ private
51
+
52
+ def assert_pivotal_receives(event_data, name, description)
53
+ http_stubs.post "services/v3/projects/123/stories" do |env|
54
+ body = Hash[URI.decode_www_form(env[:body])]
55
+ expect(env[:request_headers]["X-TrackerToken"]).to eq("token")
56
+ expect(body["story[name]"]).to eq(name)
57
+ expect(body["story[description]"]).to eq(description)
58
+ [200, {}, "<doc><story><id>123</id><url>http://pivotaltracker.com/n/projects/123/stories/123</url></story></doc>"]
59
+ end
60
+ receive_event(event_data)
61
+ end
62
+
63
+ def receive_event(event_data = nil)
64
+ service_receive(
65
+ CC::Service::PivotalTracker,
66
+ { api_token: "token", project_id: "123" },
67
+ event_data || event(:quality, from: "C", to: "D"),
68
+ )
69
+ end
70
+ end
@@ -1,42 +1,38 @@
1
- # encoding: UTF-8
2
-
3
- require File.expand_path('../helper', __FILE__)
4
-
5
- class TestSlack < CC::Service::TestCase
6
- def test_test_hook
1
+ describe CC::Service::Slack, type: :service do
2
+ it "test hook" do
7
3
  assert_slack_receives(
8
4
  nil,
9
5
  { name: "test", repo_name: "rails" },
10
- "[rails] This is a test of the Slack service hook"
6
+ "[rails] This is a test of the Slack service hook",
11
7
  )
12
8
  end
13
9
 
14
- def test_coverage_improved
10
+ it "coverage improved" do
15
11
  e = event(:coverage, to: 90.2, from: 80)
16
12
 
17
13
  assert_slack_receives("#38ae6f", e, [
18
14
  "[Example]",
19
15
  "<https://codeclimate.com/repos/1/feed|Test coverage>",
20
16
  "has improved to 90.2% (+10.2%)",
21
- "(<https://codeclimate.com/repos/1/compare|Compare>)"
17
+ "(<https://codeclimate.com/repos/1/compare|Compare>)",
22
18
  ].join(" "))
23
19
  end
24
20
 
25
- def test_coverage_declined
21
+ it "coverage declined" do
26
22
  e = event(:coverage, to: 88.6, from: 94.6)
27
23
 
28
24
  assert_slack_receives("#ed2f00", e, [
29
25
  "[Example]",
30
26
  "<https://codeclimate.com/repos/1/feed|Test coverage>",
31
27
  "has declined to 88.6% (-6.0%)",
32
- "(<https://codeclimate.com/repos/1/compare|Compare>)"
28
+ "(<https://codeclimate.com/repos/1/compare|Compare>)",
33
29
  ].join(" "))
34
30
  end
35
31
 
36
- def test_single_vulnerability
32
+ it "single vulnerability" do
37
33
  e = event(:vulnerability, vulnerabilities: [
38
- { "warning_type" => "critical" }
39
- ])
34
+ { "warning_type" => "critical" },
35
+ ])
40
36
 
41
37
  assert_slack_receives(nil, e, [
42
38
  "[Example]",
@@ -45,11 +41,11 @@ class TestSlack < CC::Service::TestCase
45
41
  ].join(" "))
46
42
  end
47
43
 
48
- def test_single_vulnerability_with_location
44
+ it "single vulnerability with location" do
49
45
  e = event(:vulnerability, vulnerabilities: [{
50
- "warning_type" => "critical",
51
- "location" => "app/user.rb line 120"
52
- }])
46
+ "warning_type" => "critical",
47
+ "location" => "app/user.rb line 120",
48
+ }])
53
49
 
54
50
  assert_slack_receives(nil, e, [
55
51
  "[Example]",
@@ -58,14 +54,14 @@ class TestSlack < CC::Service::TestCase
58
54
  ].join(" "))
59
55
  end
60
56
 
61
- def test_multiple_vulnerabilities
57
+ it "multiple vulnerabilities" do
62
58
  e = event(:vulnerability, warning_type: "critical", vulnerabilities: [{
63
- "warning_type" => "unused",
64
- "location" => "unused"
65
- }, {
66
- "warning_type" => "unused",
67
- "location" => "unused"
68
- }])
59
+ "warning_type" => "unused",
60
+ "location" => "unused",
61
+ }, {
62
+ "warning_type" => "unused",
63
+ "location" => "unused",
64
+ }])
69
65
 
70
66
  assert_slack_receives(nil, e, [
71
67
  "[Example]",
@@ -74,49 +70,47 @@ class TestSlack < CC::Service::TestCase
74
70
  ].join(" "))
75
71
  end
76
72
 
77
- def test_quality_alert_with_new_constants
73
+ it "quality alert with new constants" do
78
74
  data = { "name" => "snapshot", "repo_name" => "Rails",
79
- "new_constants" => [{"name" => "Foo", "to" => {"rating" => "D"}}, {"name" => "bar.js", "to" => {"rating" => "F"}}],
75
+ "new_constants" => [{ "name" => "Foo", "to" => { "rating" => "D" } }, { "name" => "bar.js", "to" => { "rating" => "F" } }],
80
76
  "changed_constants" => [],
81
77
  "compare_url" => "https://codeclimate.com/repos/1/compare/a...z" }
82
78
 
83
79
  response = assert_slack_receives(CC::Service::Slack::RED_HEX, data,
84
- """Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
80
+ """Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
85
81
 
86
82
  • _Foo_ was just created and is a *D*
87
83
  • _bar.js_ was just created and is an *F*""")
88
84
 
89
- assert response[:ok]
85
+ expect(response[:ok]).to eq(true)
90
86
  end
91
87
 
92
- def test_quality_alert_with_new_constants_and_declined_constants
88
+ it "quality alert with new constants and declined constants" do
93
89
  data = { "name" => "snapshot", "repo_name" => "Rails",
94
- "new_constants" => [{"name" => "Foo", "to" => {"rating" => "D"}}],
95
- "changed_constants" => [{"name" => "bar.js", "from" => {"rating" => "A"}, "to" => {"rating" => "F"}}],
90
+ "new_constants" => [{ "name" => "Foo", "to" => { "rating" => "D" } }],
91
+ "changed_constants" => [{ "name" => "bar.js", "from" => { "rating" => "A" }, "to" => { "rating" => "F" } }],
96
92
  "compare_url" => "https://codeclimate.com/repos/1/compare/a...z" }
97
93
 
98
94
  assert_slack_receives(CC::Service::Slack::RED_HEX, data,
99
- """Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
95
+ """Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
100
96
 
101
97
  • _Foo_ was just created and is a *D*
102
98
  • _bar.js_ just declined from an *A* to an *F*""")
103
99
  end
104
100
 
105
- def test_quality_alert_with_new_constants_and_declined_constants_overflown
101
+ it "quality alert with new constants and declined constants overflown" do
106
102
  data = { "name" => "snapshot", "repo_name" => "Rails",
107
- "new_constants" => [{"name" => "Foo", "to" => {"rating" => "D"}}],
103
+ "new_constants" => [{ "name" => "Foo", "to" => { "rating" => "D" } }],
108
104
  "changed_constants" => [
109
- {"name" => "bar.js", "from" => {"rating" => "A"}, "to" => {"rating" => "F"}},
110
- {"name" => "baz.js", "from" => {"rating" => "B"}, "to" => {"rating" => "D"}},
111
- {"name" => "Qux", "from" => {"rating" => "A"}, "to" => {"rating" => "D"}}
105
+ { "name" => "bar.js", "from" => { "rating" => "A" }, "to" => { "rating" => "F" } },
106
+ { "name" => "baz.js", "from" => { "rating" => "B" }, "to" => { "rating" => "D" } },
107
+ { "name" => "Qux", "from" => { "rating" => "A" }, "to" => { "rating" => "D" } },
112
108
  ],
113
109
  "compare_url" => "https://codeclimate.com/repos/1/compare/a...z",
114
- "details_url" => "https://codeclimate.com/repos/1/feed"
115
- }
116
-
110
+ "details_url" => "https://codeclimate.com/repos/1/feed" }
117
111
 
118
112
  assert_slack_receives(CC::Service::Slack::RED_HEX, data,
119
- """Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
113
+ """Quality alert triggered for *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
120
114
 
121
115
  • _Foo_ was just created and is a *D*
122
116
  • _bar.js_ just declined from an *A* to an *F*
@@ -125,39 +119,35 @@ class TestSlack < CC::Service::TestCase
125
119
  And <https://codeclimate.com/repos/1/feed|1 other change>""")
126
120
  end
127
121
 
128
- def test_quality_improvements
122
+ it "quality improvements" do
129
123
  data = { "name" => "snapshot", "repo_name" => "Rails",
130
124
  "new_constants" => [],
131
125
  "changed_constants" => [
132
- {"name" => "bar.js", "from" => {"rating" => "F"}, "to" => {"rating" => "A"}},
126
+ { "name" => "bar.js", "from" => { "rating" => "F" }, "to" => { "rating" => "A" } },
133
127
  ],
134
128
  "compare_url" => "https://codeclimate.com/repos/1/compare/a...z",
135
- "details_url" => "https://codeclimate.com/repos/1/feed"
136
- }
137
-
129
+ "details_url" => "https://codeclimate.com/repos/1/feed" }
138
130
 
139
131
  assert_slack_receives(CC::Service::Slack::GREEN_HEX, data,
140
- """Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
132
+ """Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
141
133
 
142
134
  • _bar.js_ just improved from an *F* to an *A*""")
143
135
  end
144
136
 
145
- def test_quality_improvements_overflown
137
+ it "quality improvements overflown" do
146
138
  data = { "name" => "snapshot", "repo_name" => "Rails",
147
139
  "new_constants" => [],
148
140
  "changed_constants" => [
149
- {"name" => "Foo", "from" => {"rating" => "F"}, "to" => {"rating" => "A"}},
150
- {"name" => "bar.js", "from" => {"rating" => "D"}, "to" => {"rating" => "B"}},
151
- {"name" => "baz.js", "from" => {"rating" => "D"}, "to" => {"rating" => "A"}},
152
- {"name" => "Qux", "from" => {"rating" => "F"}, "to" => {"rating" => "A"}},
141
+ { "name" => "Foo", "from" => { "rating" => "F" }, "to" => { "rating" => "A" } },
142
+ { "name" => "bar.js", "from" => { "rating" => "D" }, "to" => { "rating" => "B" } },
143
+ { "name" => "baz.js", "from" => { "rating" => "D" }, "to" => { "rating" => "A" } },
144
+ { "name" => "Qux", "from" => { "rating" => "F" }, "to" => { "rating" => "A" } },
153
145
  ],
154
146
  "compare_url" => "https://codeclimate.com/repos/1/compare/a...z",
155
- "details_url" => "https://codeclimate.com/repos/1/feed"
156
- }
157
-
147
+ "details_url" => "https://codeclimate.com/repos/1/feed" }
158
148
 
159
149
  assert_slack_receives(CC::Service::Slack::GREEN_HEX, data,
160
- """Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
150
+ """Quality improvements in *Rails* (<https://codeclimate.com/repos/1/compare/a...z|Compare>)
161
151
 
162
152
  • _Foo_ just improved from an *F* to an *A*
163
153
  • _bar.js_ just improved from a *D* to a *B*
@@ -166,57 +156,56 @@ And <https://codeclimate.com/repos/1/feed|1 other change>""")
166
156
  And <https://codeclimate.com/repos/1/feed|1 other improvement>""")
167
157
  end
168
158
 
169
- def test_received_success
159
+ it "received success" do
170
160
  response = assert_slack_receives(
171
161
  nil,
172
162
  { name: "test", repo_name: "rails" },
173
- "[rails] This is a test of the Slack service hook"
163
+ "[rails] This is a test of the Slack service hook",
174
164
  )
175
- assert_true response[:ok]
176
- assert_equal "Test message sent", response[:message]
165
+ expect(response[:ok]).to eq(true)
166
+ expect(response[:message]).to eq("Test message sent")
177
167
  end
178
168
 
179
- def test_receive_test
180
- @stubs.post '/token' do |env|
181
- [200, {}, 'ok']
169
+ it "receive test" do
170
+ http_stubs.post "/token" do |_env|
171
+ [200, {}, "ok"]
182
172
  end
183
173
 
184
174
  response = receive_event(name: "test")
185
175
 
186
- assert_equal "Test message sent", response[:message]
176
+ expect(response[:message]).to eq("Test message sent")
187
177
  end
188
178
 
189
- def test_no_changes_in_snapshot
179
+ it "no changes in snapshot" do
190
180
  data = { "name" => "snapshot", "repo_name" => "Rails",
191
181
  "new_constants" => [],
192
- "changed_constants" => [],
193
- }
182
+ "changed_constants" => [] }
194
183
  response = receive_event(data)
195
184
 
196
- assert_equal false, response[:ok]
197
- assert response[:ignored]
185
+ expect(response[:ok]).to eq(false)
186
+ expect(response[:ignored]).to eq(true)
198
187
  end
199
188
 
200
189
  private
201
190
 
202
191
  def assert_slack_receives(color, event_data, expected_body)
203
- @stubs.post '/token' do |env|
192
+ http_stubs.post "/token" do |env|
204
193
  body = JSON.parse(env[:body])
205
194
  attachment = body["attachments"].first
206
195
  field = attachment["fields"].first
207
- assert_equal color, attachment["color"] # may be nil
208
- assert_equal expected_body, attachment["fallback"]
209
- assert_equal expected_body, field["value"]
210
- [200, {}, 'ok']
196
+ attachment["color"] # may be expect(nil).to eq(color)
197
+ expect(attachment["fallback"]).to eq(expected_body)
198
+ expect(field["value"]).to eq(expected_body)
199
+ [200, {}, "ok"]
211
200
  end
212
201
  receive_event(event_data)
213
202
  end
214
203
 
215
204
  def receive_event(event_data = nil)
216
- receive(
205
+ service_receive(
217
206
  CC::Service::Slack,
218
207
  { webhook_url: "http://api.slack.com/token", channel: "#general" },
219
- event_data || event(:quality, from: "C", to: "D")
208
+ event_data || event(:quality, from: "C", to: "D"),
220
209
  )
221
210
  end
222
211
  end