spec/namely/resource_gateway_spec.rb in namely-0.0.1 vs spec/namely/resource_gateway_spec.rb in namely-0.1.0
- old
+ new
@@ -1,14 +1,22 @@
require "spec_helper"
describe Namely::ResourceGateway do
+ def access_token
+ ENV.fetch("TEST_ACCESS_TOKEN")
+ end
+
+ def subdomain
+ ENV.fetch("TEST_SUBDOMAIN")
+ end
+
def gateway
@gateway ||= Namely::ResourceGateway.new(
- access_token: Namely.configuration.access_token,
+ access_token: access_token,
endpoint: "widgets",
resource_name: "widgets",
- subdomain: Namely.configuration.subdomain
+ subdomain: subdomain,
)
end
def valid_id
"this-is-a-valid-id"
@@ -20,14 +28,14 @@
describe "#json_index" do
it "returns the parsed JSON representation of #index" do
stub_request(
:get,
- "https://#{Namely.configuration.subdomain}.namely.com/api/v1/widgets"
+ "https://#{subdomain}.namely.com/api/v1/widgets"
).with(
query: {
- access_token: Namely.configuration.access_token,
+ access_token: access_token,
limit: :all
}
).to_return(
body: "{\"widgets\": [\"woo!\"]}",
status: 200
@@ -39,14 +47,14 @@
describe "#json_show" do
it "returns the parsed JSON representation of #show" do
stub_request(
:get,
- "https://#{Namely.configuration.subdomain}.namely.com/api/v1/widgets/#{valid_id}"
+ "https://#{subdomain}.namely.com/api/v1/widgets/#{valid_id}"
).with(
query: {
- access_token: Namely.configuration.access_token
+ access_token: access_token
}
).to_return(
body: "{\"widgets\": [{\"name\": \"wilbur\", \"favorite_color\": \"chartreuse\"}]}",
status: 200
)
@@ -60,14 +68,14 @@
describe "#show_head" do
it "returns an empty response if it succeeds" do
stub_request(
:head,
- "https://#{Namely.configuration.subdomain}.namely.com/api/v1/widgets/#{valid_id}"
+ "https://#{subdomain}.namely.com/api/v1/widgets/#{valid_id}"
).with(
query: {
- access_token: Namely.configuration.access_token
+ access_token: access_token
}
).to_return(
body: "",
status: 200
)
@@ -76,13 +84,13 @@
end
it "raises a RestClient::ResourceNotFound error if it fails" do
stub_request(
:head,
- "https://#{Namely.configuration.subdomain}.namely.com/api/v1/widgets/#{invalid_id}"
+ "https://#{subdomain}.namely.com/api/v1/widgets/#{invalid_id}"
).with(
query: {
- access_token: Namely.configuration.access_token
+ access_token: access_token
}
).to_return(
status: 404
)