Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constrain spec file lines to 80 characters #38

Merged
merged 1 commit into from
Apr 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ AllCops:
- .bundle/**/*
- bin/**/*

Metrics/LineLength:
Exclude:
- spec/**/*

Style/AccessModifierIndentation:
EnforcedStyle: outdent

Expand Down
53 changes: 36 additions & 17 deletions spec/pagerduty/http_transport_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,45 @@
describe "provides the correct request" do
Then {
expect(post).to have_received(:body=).with(
'{"event_type":"trigger","service_key":"test-srvc-key","description":"test-desc","details":{"key":"value"}}',
'{"event_type":"trigger",'\
'"service_key":"test-srvc-key",'\
'"description":"test-desc",'\
'"details":{"key":"value"}}',
)
}
end

describe "handles all responses" do
context "PagerDuty successfully creates the incident" do
Given { allow(http).to receive(:request).and_return(response_with_body(<<-JSON)) }
{
"status": "success",
"incident_key": "My Incident Key",
"message": "Event processed"
}
JSON
Given {
allow(http)
.to receive(:request)
.and_return(response_with_body(<<-JSON))
{
"status": "success",
"incident_key": "My Incident Key",
"message": "Event processed"
}
JSON
}

Then { expect(response).to include("status" => "success") }
Then { expect(response).to include("incident_key" => "My Incident Key") }
Then {
expect(response).to include("incident_key" => "My Incident Key")
}
end

context "PagerDuty fails to create the incident" do
Given { allow(http).to receive(:request).and_return(response_with_body(<<-JSON)) }
{
"status": "failure",
"message": "Event not processed"
}
JSON
Given {
allow(http)
.to receive(:request)
.and_return(response_with_body(<<-JSON))
{
"status": "failure",
"message": "Event not processed"
}
JSON
}
Then { expect(response).to include("status" => "failure") }
Then { expect(response).to_not include("incident_key") }
end
Expand All @@ -63,9 +76,13 @@

describe "HTTPS use" do
Then { expect(http).to have_received(:use_ssl=).with(true) }
Then { expect(http).to have_received(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER) }
Then { expect(http).to_not have_received(:ca_path=) }
Then { expect(http).to_not have_received(:verify_depth=) }
Then {
expect(http)
.to have_received(:verify_mode=)
.with(OpenSSL::SSL::VERIFY_PEER)
}
end

describe "timeouts" do
Expand All @@ -75,7 +92,9 @@
end

def standard_response
response_with_body '{ "status": "success", "incident_key": "My Incident Key" }'
response_with_body(
'{ "status": "success", "incident_key": "My Incident Key" }',
)
end

def response_with_body(body)
Expand Down
57 changes: 47 additions & 10 deletions spec/pagerduty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

describe "#trigger" do
describe "provides the correct request" do
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
Given {
allow(transport)
.to receive(:send_payload)
.and_return(standard_response)
}

context "no options" do
When(:incident) { pagerduty.trigger("a-test-description") }
Expand Down Expand Up @@ -74,7 +78,11 @@
end

context "PagerDuty responds with HTTP bad request" do
Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
Given {
allow(transport)
.to receive(:send_payload)
.and_raise(Net::HTTPServerException.new(nil, nil))
}
When(:incident) { pagerduty.trigger("description") }
Then { expect(incident).to have_raised Net::HTTPServerException }
end
Expand All @@ -95,7 +103,11 @@

describe "#acknowledge" do
describe "provides the correct request" do
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
Given {
allow(transport)
.to receive(:send_payload)
.and_return(standard_response)
}

context "no args" do
When(:acknowledge) { incident.acknowledge }
Expand All @@ -121,7 +133,9 @@
end

context "a description and details" do
When(:acknowledge) { incident.acknowledge("test-description", my: "detail") }
When(:acknowledge) {
incident.acknowledge("test-description", my: "detail")
}
Then {
expect(transport).to have_received(:send_payload).with(
event_type: "acknowledge",
Expand Down Expand Up @@ -160,7 +174,11 @@
end

context "PagerDuty responds with HTTP bad request" do
Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
Given {
allow(transport)
.to receive(:send_payload)
.and_raise(Net::HTTPServerException.new(nil, nil))
}
When(:acknowledge) { incident.acknowledge }
Then { expect(acknowledge).to have_failed Net::HTTPServerException }
end
Expand All @@ -169,7 +187,11 @@

describe "#resolve" do
describe "provides the correct request" do
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
Given {
allow(transport)
.to receive(:send_payload)
.and_return(standard_response)
}

context "no args" do
When(:resolve) { incident.resolve }
Expand Down Expand Up @@ -233,7 +255,11 @@
end

context "PagerDuty responds with HTTP bad request" do
Given { allow(transport).to receive(:send_payload).and_raise(Net::HTTPServerException.new(nil, nil)) }
Given {
allow(transport)
.to receive(:send_payload)
.and_raise(Net::HTTPServerException.new(nil, nil))
}
When(:resolve) { incident.resolve }
Then { expect(resolve).to have_failed Net::HTTPServerException }
end
Expand All @@ -242,7 +268,11 @@

describe "#trigger" do
describe "provides the correct request" do
Given { allow(transport).to receive(:send_payload).and_return(standard_response) }
Given {
allow(transport)
.to receive(:send_payload)
.and_return(standard_response)
}

context "no options" do
Given(:incident_key) { "instance incident_key" }
Expand All @@ -258,7 +288,12 @@
end

context "with incident_key option" do
When(:trigger) { incident.trigger("description", incident_key: "method param incident_key") }
When(:trigger) {
incident.trigger(
"description",
incident_key: "method param incident_key",
)
}
Then {
expect(transport).to have_received(:send_payload).with(
incident_key: "method param incident_key",
Expand All @@ -281,7 +316,9 @@ def standard_response
Given(:api_response) { double }
Given(:message) { "a test error message" }

When(:pagerduty_exception) { PagerdutyException.new(pagerduty_instance, api_response, message) }
When(:pagerduty_exception) {
PagerdutyException.new(pagerduty_instance, api_response, message)
}

Then { pagerduty_exception.pagerduty_instance == pagerduty_instance }
Then { pagerduty_exception.api_response == api_response }
Expand Down