openstax_exchange 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +15 -0
  2. data/.rspec +1 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +4 -0
  7. data/MIT-LICENSE +3 -1
  8. data/README.md +58 -20
  9. data/Rakefile +5 -13
  10. data/exchange-client.gemspec +30 -0
  11. data/lib/openstax/exchange/client_instance.rb +23 -0
  12. data/lib/openstax/exchange/configuration.rb +12 -0
  13. data/lib/openstax/exchange/exceptions.rb +21 -0
  14. data/lib/openstax/exchange/exchange.rb +65 -0
  15. data/lib/openstax/exchange/fake_client/configuration.rb +13 -0
  16. data/lib/openstax/exchange/fake_client/fake_client.rb +71 -0
  17. data/lib/openstax/exchange/real_client/real_client.rb +76 -0
  18. data/lib/openstax/exchange/version.rb +1 -1
  19. data/lib/openstax_exchange.rb +8 -112
  20. data/spec/cassettes/OpenStax_Exchange/client_instance_configuration/can_be_configured_to_use_a_real_exchange_client.yml +48 -0
  21. data/spec/cassettes/OpenStax_Exchange/internal_client_instance/_client_defaults_to_a_real_exchange_client.yml +48 -0
  22. data/spec/cassettes/OpenStax_Exchange/internal_client_instance/_reset_causes_a_new_client_object_to_be_returned_by_client.yml +48 -0
  23. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_create_identifier/success/creates_a_distinct_identifer_per_invokation.yml +146 -0
  24. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_create_identifier/success/creates_and_returns_a_new_identifier.yml +97 -0
  25. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/invalid_platform_id/raises_an_exception.yml +52 -0
  26. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/invalid_platform_secret/raises_an_exception.yml +52 -0
  27. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_initialize/success/initializes_the_authentication_token.yml +48 -0
  28. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/duplicate_identifer_resource_trial_triplet/raises_an_exception.yml +194 -0
  29. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/invalid_resource_string/raises_an_exception.yml +145 -0
  30. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/success/allows_answers_with_distinct_identifiers_to_be_saved.yml +244 -0
  31. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/success/allows_answers_with_distinct_resources_to_be_saved.yml +195 -0
  32. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/success/allows_answers_with_distinct_trials_to_be_saved.yml +195 -0
  33. data/spec/cassettes/OpenStax_Exchange_RealClient/behaves_like_exchange_client_api_v1/_record_multiple_choice_answer/success/creates_a_multiple_choice_answer_associated_with_the_given_identifier.yml +146 -0
  34. data/spec/lib/openstax/exchange/client_configuration_spec.rb +58 -0
  35. data/spec/lib/openstax/exchange/fake_client_v1_spec.rb +14 -0
  36. data/spec/lib/openstax/exchange/real_client_v1_spec.rb +9 -0
  37. data/spec/lib/openstax/exchange/shared_examples_for_exchange_client_v1.rb +208 -0
  38. data/spec/spec_helper.rb +52 -38
  39. metadata +97 -100
  40. checksums.yaml +0 -15
  41. data/spec/dummy/README.md +0 -1
  42. data/spec/dummy/Rakefile +0 -7
  43. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  44. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  45. data/spec/dummy/app/controllers/api/dummy_controller.rb +0 -11
  46. data/spec/dummy/app/controllers/api/events_controller.rb +0 -7
  47. data/spec/dummy/app/controllers/application_controller.rb +0 -7
  48. data/spec/dummy/app/controllers/oauth_controller.rb +0 -8
  49. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  50. data/spec/dummy/config.ru +0 -4
  51. data/spec/dummy/config/application.rb +0 -55
  52. data/spec/dummy/config/boot.rb +0 -10
  53. data/spec/dummy/config/database.yml +0 -25
  54. data/spec/dummy/config/environment.rb +0 -5
  55. data/spec/dummy/config/environments/development.rb +0 -29
  56. data/spec/dummy/config/environments/production.rb +0 -69
  57. data/spec/dummy/config/environments/test.rb +0 -35
  58. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  59. data/spec/dummy/config/initializers/inflections.rb +0 -15
  60. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  61. data/spec/dummy/config/initializers/openstax_exchange.rb +0 -10
  62. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  63. data/spec/dummy/config/initializers/session_store.rb +0 -8
  64. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  65. data/spec/dummy/config/locales/en.yml +0 -5
  66. data/spec/dummy/config/routes.rb +0 -11
  67. data/spec/dummy/db/development.sqlite3 +0 -0
  68. data/spec/dummy/db/schema.rb +0 -16
  69. data/spec/dummy/db/test.sqlite3 +0 -0
  70. data/spec/dummy/log/development.log +0 -929
  71. data/spec/dummy/log/test.log +0 -46753
  72. data/spec/dummy/public/404.html +0 -26
  73. data/spec/dummy/public/422.html +0 -26
  74. data/spec/dummy/public/500.html +0 -25
  75. data/spec/dummy/public/favicon.ico +0 -0
  76. data/spec/dummy/script/rails +0 -6
  77. data/spec/lib/openstax_exchange_spec.rb +0 -23
@@ -0,0 +1,146 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://123:abc@localhost:3003/oauth/token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: grant_type=client_credentials
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ X-Frame-Options:
22
+ - SAMEORIGIN
23
+ X-Xss-Protection:
24
+ - 1; mode=block
25
+ X-Content-Type-Options:
26
+ - nosniff
27
+ Cache-Control:
28
+ - no-store
29
+ Pragma:
30
+ - no-cache
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Etag:
34
+ - W/"e463908024e5712415722596d2aa197d"
35
+ X-Request-Id:
36
+ - e0cc9069-fabe-447e-8f39-3ea55a2ae601
37
+ X-Runtime:
38
+ - '0.015996'
39
+ Connection:
40
+ - close
41
+ Server:
42
+ - thin
43
+ body:
44
+ encoding: US-ASCII
45
+ string: ! '{"access_token":"63cf088605315a592d872458afbdd26eb691a7ebd4db117215ebc2cd84829d45","token_type":"bearer"}'
46
+ http_version:
47
+ recorded_at: Mon, 12 Jan 2015 21:08:52 GMT
48
+ - request:
49
+ method: post
50
+ uri: http://localhost:3003/api/identifiers
51
+ body:
52
+ encoding: US-ASCII
53
+ string: ''
54
+ headers:
55
+ User-Agent:
56
+ - Faraday v0.9.0
57
+ Accept:
58
+ - application/vnd.exchange.openstax.v1
59
+ Authorization:
60
+ - Bearer 63cf088605315a592d872458afbdd26eb691a7ebd4db117215ebc2cd84829d45
61
+ Content-Length:
62
+ - '0'
63
+ response:
64
+ status:
65
+ code: 201
66
+ message: Created
67
+ headers:
68
+ X-Frame-Options:
69
+ - SAMEORIGIN
70
+ X-Xss-Protection:
71
+ - 1; mode=block
72
+ X-Content-Type-Options:
73
+ - nosniff
74
+ Content-Type:
75
+ - application/json; charset=utf-8
76
+ Etag:
77
+ - W/"94c76c22e48adee6850f7f758130929a"
78
+ Cache-Control:
79
+ - max-age=0, private, must-revalidate
80
+ Set-Cookie:
81
+ - _exercises_session=Y0FCSkN1L21TRkp0S2xJNkxuRGJUZkdNSjJML3F5NVRsdmd4WUlqaTdiczZ2WDRXcE1MTDFhVFFHRmxzL1R5Y0pHRlpRTzJYRzNKSmxnUzZIUFlHR1E9PS0tVFRkTkdBWk9YaGw3Q1A4M29NWmxiUT09--a105cf2f6eb8f7307466b070661c139095608ea5;
82
+ path=/; HttpOnly
83
+ - request_method=POST; path=/
84
+ X-Request-Id:
85
+ - ecbb2f11-eb79-4f06-91ed-3a511c13e2f3
86
+ X-Runtime:
87
+ - '0.040816'
88
+ Connection:
89
+ - close
90
+ Server:
91
+ - thin
92
+ body:
93
+ encoding: US-ASCII
94
+ string: ! '{"identifier":"3aa2504cbe2e8b8e2f7e3834c6c1324ffcd50b29872bcdbe77d1c3587bd719ae"}'
95
+ http_version:
96
+ recorded_at: Mon, 12 Jan 2015 21:08:52 GMT
97
+ - request:
98
+ method: post
99
+ uri: http://localhost:3003/api/events/platforms/multiple_choices
100
+ body:
101
+ encoding: UTF-8
102
+ string: ! '{"identifier":"3aa2504cbe2e8b8e2f7e3834c6c1324ffcd50b29872bcdbe77d1c3587bd719ae","resource":"http://exercises.openstax.org/exercises/1234","trial":"1","answer":"answer_string"}'
103
+ headers:
104
+ User-Agent:
105
+ - Faraday v0.9.0
106
+ Accept:
107
+ - application/vnd.exchange.openstax.v1
108
+ Authorization:
109
+ - Bearer 63cf088605315a592d872458afbdd26eb691a7ebd4db117215ebc2cd84829d45
110
+ Content-Type:
111
+ - application/x-www-form-urlencoded
112
+ response:
113
+ status:
114
+ code: 201
115
+ message: Created
116
+ headers:
117
+ X-Frame-Options:
118
+ - SAMEORIGIN
119
+ X-Xss-Protection:
120
+ - 1; mode=block
121
+ X-Content-Type-Options:
122
+ - nosniff
123
+ Content-Type:
124
+ - application/json; charset=utf-8
125
+ Etag:
126
+ - W/"d044e24bdcdf0b2ff8316bbf53e25f14"
127
+ Cache-Control:
128
+ - max-age=0, private, must-revalidate
129
+ Set-Cookie:
130
+ - _exercises_session=RUdNUXpxRkR1YzRlcE05MFJKV3NRQnJIaUU4RzhHTW9pREtzWUd2TjRiMGdZM2RsZlhmaHZKdlJ1dDRRRi9GUVlkZUo2anBFbkw5ZjErdU1Sb3Q1VVE9PS0tb3NIaTJoQ3djbkpzaWZhU0dkQ3hXUT09--b863b16466f2fc8176a22fa602c21184415f14ed;
131
+ path=/; HttpOnly
132
+ - request_method=POST; path=/
133
+ X-Request-Id:
134
+ - 3b6c238a-5709-4d7c-a8fe-69c8e96e9669
135
+ X-Runtime:
136
+ - '0.086874'
137
+ Connection:
138
+ - close
139
+ Server:
140
+ - thin
141
+ body:
142
+ encoding: US-ASCII
143
+ string: ! '{"identifier":"3aa2504cbe2e8b8e2f7e3834c6c1324ffcd50b29872bcdbe77d1c3587bd719ae","resource":"http://exercises.openstax.org/exercises/1234","trial":"1","created_at":"2015-01-12T21:08:52.423Z","answer_type":"multiple-choice","answer":"answer_string"}'
144
+ http_version:
145
+ recorded_at: Mon, 12 Jan 2015 21:08:52 GMT
146
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenStax::Exchange, vcr: VCR_OPTS do
4
+
5
+ before(:each) do
6
+ OpenStax::Exchange.configure do |config|
7
+ config.client_platform_id = DEFAULT_CLIENT_PLATFORM_ID
8
+ config.client_platform_secret = DEFAULT_CLIENT_PLATFORM_SECRET
9
+ config.client_server_url = client_server_url
10
+ config.client_api_version = DEFAULT_CLIENT_API_VERSION
11
+ end
12
+
13
+ OpenStax::Exchange::FakeClient.configure do |config|
14
+ config.registered_platforms = {DEFAULT_CLIENT_PLATFORM_ID => DEFAULT_CLIENT_PLATFORM_SECRET}
15
+ config.server_url = client_server_url
16
+ config.supported_api_versions = [ DEFAULT_CLIENT_API_VERSION ]
17
+ end
18
+ end
19
+
20
+ context "internal client instance" do
21
+ it "#client defaults to a real exchange client" do
22
+ client = OpenStax::Exchange.send(:client)
23
+ expect(client.is_real_client?).to be_truthy
24
+ end
25
+
26
+ it "#client returns the same client object on successive calls" do
27
+ client_object_id1 = OpenStax::Exchange.send(:client).object_id
28
+ client_object_id2 = OpenStax::Exchange.send(:client).object_id
29
+ expect(client_object_id1).to eq(client_object_id2)
30
+ end
31
+
32
+ it "#reset! causes a new client object to be returned by #client" do
33
+ client_object_id1 = OpenStax::Exchange.send(:client).object_id
34
+ OpenStax::Exchange.reset!
35
+ client_object_id2 = OpenStax::Exchange.send(:client).object_id
36
+ expect(client_object_id1).to_not eq(client_object_id2)
37
+ end
38
+ end
39
+
40
+ context "client instance configuration" do
41
+ before(:each) do
42
+ OpenStax::Exchange.reset!
43
+ end
44
+
45
+ it "can be configured to use a real exchange client" do
46
+ OpenStax::Exchange.use_real_client
47
+ client = OpenStax::Exchange.send(:client)
48
+ expect(client.is_real_client?).to be_truthy
49
+ end
50
+
51
+ it "can be configured to use a fake exchange client" do
52
+ OpenStax::Exchange.use_fake_client
53
+ client = OpenStax::Exchange.send(:client)
54
+ expect(client.is_real_client?).to be_falsy
55
+ end
56
+ end
57
+
58
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenStax::Exchange::FakeClient do
4
+ before(:each) do
5
+ OpenStax::Exchange.use_fake_client
6
+ OpenStax::Exchange::FakeClient.configure do |config|
7
+ config.registered_platforms = {DEFAULT_CLIENT_PLATFORM_ID => DEFAULT_CLIENT_PLATFORM_SECRET}
8
+ config.server_url = client_server_url
9
+ config.supported_api_versions = [API_VERSION_V1]
10
+ end
11
+ end
12
+
13
+ it_behaves_like "exchange client api v1"
14
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenStax::Exchange::RealClient, vcr: VCR_OPTS do
4
+ before(:each) do
5
+ OpenStax::Exchange::use_real_client
6
+ end
7
+
8
+ it_behaves_like "exchange client api v1"
9
+ end
@@ -0,0 +1,208 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.shared_examples "exchange client api v1" do
4
+
5
+ before(:each) do
6
+ OpenStax::Exchange.reset!
7
+ OpenStax::Exchange.configure do |config|
8
+ config.client_platform_id = DEFAULT_CLIENT_PLATFORM_ID
9
+ config.client_platform_secret = DEFAULT_CLIENT_PLATFORM_SECRET
10
+ config.client_server_url = client_server_url
11
+ config.client_api_version = API_VERSION_V1
12
+ end
13
+ end
14
+
15
+ describe "#initialize" do
16
+ context "success" do
17
+ it "initializes the authentication token" do
18
+ client = OpenStax::Exchange.send(:client)
19
+ expect(client.token).to_not be_nil
20
+ end
21
+ end
22
+ context "invalid server" do
23
+ it "raises an exception" do
24
+ OpenStax::Exchange.configure do |config|
25
+ config.client_server_url = client_server_url(host: 'this.is.a.fake.address')
26
+ end
27
+ expect {
28
+ OpenStax::Exchange.send(:client)
29
+ }.to raise_error(OpenStax::Exchange::ClientError)
30
+ end
31
+ end
32
+ context "invalid port" do
33
+ it "raises an exception" do
34
+ OpenStax::Exchange.configure do |config|
35
+ config.client_server_url = client_server_url(port: 9999)
36
+ end
37
+ expect {
38
+ OpenStax::Exchange.send(:client)
39
+ }.to raise_error(OpenStax::Exchange::ClientError)
40
+ end
41
+ end
42
+ context "invalid platform id" do
43
+ it "raises an exception" do
44
+ OpenStax::Exchange.configure do |config|
45
+ config.client_platform_id = '999'
46
+ end
47
+ expect {
48
+ OpenStax::Exchange.send(:client)
49
+ }.to raise_error(OpenStax::Exchange::ClientError)
50
+ end
51
+ end
52
+ context "invalid platform secret" do
53
+ it "raises an exception" do
54
+ OpenStax::Exchange.configure do |config|
55
+ config.client_platform_secret = 'not_the_secret'
56
+ end
57
+ expect {
58
+ OpenStax::Exchange.send(:client)
59
+ }.to raise_error(OpenStax::Exchange::ClientError)
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "#create_identifier" do
65
+ context "success" do
66
+ it "creates and returns a new identifier" do
67
+ identifier = OpenStax::Exchange.create_identifier
68
+ expect(identifier).to match(/^[a-fA-F0-9]+$/)
69
+ end
70
+ it "creates a distinct identifer per invokation" do
71
+ identifier1 = OpenStax::Exchange.create_identifier
72
+ identifier2 = OpenStax::Exchange.create_identifier
73
+ expect(identifier1).to_not eq(identifier2)
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "#record_multiple_choice_answer" do
79
+ context "success" do
80
+ it "creates a multiple choice answer associated with the given identifier" do
81
+ identifier = OpenStax::Exchange.create_identifier
82
+
83
+ # must have the form of a "trusted resource"
84
+ # (Exchange app/routines/find_or_create_resource_from_url.rb:35)
85
+ resource_string = 'http://exercises.openstax.org/exercises/1234'
86
+ trial = '1'
87
+ answer_string = 'answer_string'
88
+
89
+ response = OpenStax::Exchange.record_multiple_choice_answer(
90
+ identifier, resource_string, trial, answer_string)
91
+
92
+ expect(response['identifier']).to eq(identifier)
93
+ expect(response['resource']).to eq(resource_string)
94
+ expect(response['trial']).to eq(trial)
95
+ expect(response['answer']).to eq(answer_string)
96
+ end
97
+ it "allows answers with distinct identifiers to be saved" do
98
+ identifier1 = OpenStax::Exchange.create_identifier
99
+ identifier2 = OpenStax::Exchange.create_identifier
100
+
101
+ # must have the form of a "trusted resource"
102
+ # (Exchange app/routines/find_or_create_resource_from_url.rb:35)
103
+ resource_string = 'http://exercises.openstax.org/exercises/1234'
104
+ trial = '1'
105
+ answer_string = 'answer_string'
106
+
107
+ response = nil
108
+
109
+ expect {
110
+ response = OpenStax::Exchange.record_multiple_choice_answer(
111
+ identifier1, resource_string, trial, answer_string)
112
+ }.to_not raise_error
113
+ expect(response['identifier']).to eq(identifier1)
114
+
115
+ expect {
116
+ response = OpenStax::Exchange.record_multiple_choice_answer(
117
+ identifier2, resource_string, trial, answer_string)
118
+ }.to_not raise_error
119
+ expect(response['identifier']).to eq(identifier2)
120
+ end
121
+ it "allows answers with distinct resources to be saved" do
122
+ identifier = OpenStax::Exchange.create_identifier
123
+
124
+ # must have the form of a "trusted resource"
125
+ # (Exchange app/routines/find_or_create_resource_from_url.rb:35)
126
+ resource_string1 = 'http://exercises.openstax.org/exercises/1234'
127
+ resource_string2 = 'http://exercises.openstax.org/exercises/3456'
128
+ trial = '1'
129
+ answer_string = 'answer_string'
130
+
131
+ response = nil
132
+
133
+ expect {
134
+ response = OpenStax::Exchange.record_multiple_choice_answer(
135
+ identifier, resource_string1, trial, answer_string)
136
+ }.to_not raise_error
137
+ expect(response['resource']).to eq(resource_string1)
138
+
139
+ expect {
140
+ response = OpenStax::Exchange.record_multiple_choice_answer(
141
+ identifier, resource_string2, trial, answer_string)
142
+ }.to_not raise_error
143
+ expect(response['resource']).to eq(resource_string2)
144
+ end
145
+ it "allows answers with distinct trials to be saved" do
146
+ identifier = OpenStax::Exchange.create_identifier
147
+
148
+ # must have the form of a "trusted resource"
149
+ # (Exchange app/routines/find_or_create_resource_from_url.rb:35)
150
+ resource_string = 'http://exercises.openstax.org/exercises/1234'
151
+ trial1 = '1'
152
+ trial2 = '2'
153
+ answer_string = 'answer_string'
154
+
155
+ response = nil
156
+
157
+ expect {
158
+ response = OpenStax::Exchange.record_multiple_choice_answer(
159
+ identifier, resource_string, trial1, answer_string)
160
+ }.to_not raise_error
161
+ expect(response['trial']).to eq(trial1)
162
+
163
+ expect {
164
+ response = OpenStax::Exchange.record_multiple_choice_answer(
165
+ identifier, resource_string, trial2, answer_string)
166
+ }.to_not raise_error
167
+ expect(response['trial']).to eq(trial2)
168
+ end
169
+ end
170
+ context "duplicate (identifer,resource,trial) triplet" do
171
+ it "raises an exception" do
172
+ identifier = OpenStax::Exchange.create_identifier
173
+
174
+ # must have the form of a "trusted resource"
175
+ # (Exchange app/routines/find_or_create_resource_from_url.rb:35)
176
+ resource_string = 'http://exercises.openstax.org/exercises/1234'
177
+ trial = '1'
178
+ answer_string = 'answer_string'
179
+
180
+ expect {
181
+ response = OpenStax::Exchange.record_multiple_choice_answer(
182
+ identifier, resource_string, trial, answer_string)
183
+ }.to_not raise_error
184
+
185
+ expect {
186
+ response = OpenStax::Exchange.record_multiple_choice_answer(
187
+ identifier, resource_string, trial, answer_string)
188
+ }.to raise_error(OpenStax::Exchange::ClientError)
189
+ end
190
+ end
191
+ context "invalid resource string" do
192
+ it "raises an exception" do
193
+ identifier = OpenStax::Exchange.create_identifier
194
+
195
+ # must have the form of a "trusted resource"
196
+ # (Exchange app/routines/find_or_create_resource_from_url.rb:35)
197
+ resource_string = 'http://example.com/exercises/1234'
198
+ trial = '1'
199
+ answer_string = 'answer_string'
200
+
201
+ expect {
202
+ response = OpenStax::Exchange.record_multiple_choice_answer(
203
+ identifier, resource_string, trial, answer_string)
204
+ }.to raise_error(OpenStax::Exchange::ClientError)
205
+ end
206
+ end
207
+ end
208
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,39 +1,53 @@
1
- ENV['RAILS_ENV'] ||= 'test'
2
-
3
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
4
- require 'rspec/rails'
5
-
6
- # Requires supporting ruby files with custom matchers and macros, etc,
7
- Rails.backtrace_cleaner.remove_silencers!
8
-
9
- # in spec/support/ and its subdirectories.
10
- Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
11
-
12
- RSpec.configure do |config|
13
- # ## Mock Framework
14
- #
15
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
16
- #
17
- # config.mock_with :mocha
18
- # config.mock_with :flexmock
19
- # config.mock_with :rr
20
-
21
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
22
- # config.fixture_path = "#{::Rails.root}/spec/fixtures"
23
-
24
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
25
- # examples within a transaction, remove the following line or assign false
26
- # instead of true.
27
- config.use_transactional_fixtures = true
28
-
29
- # If true, the base class of anonymous controllers will be inferred
30
- # automatically. This will be the default behavior in future versions of
31
- # rspec-rails.
32
- config.infer_base_class_for_anonymous_controllers = false
33
-
34
- # Run specs in random order to surface order dependencies. If you find an
35
- # order dependency and want to debug it, you can fix the order by providing
36
- # the seed, which is printed after each run.
37
- # --seed 1234
38
- config.order = "random"
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'vcr'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = 'spec/cassettes'
8
+ c.hook_into :webmock
9
+ c.configure_rspec_metadata!
10
+ # c.debug_logger = File.open("vcr_log.txt", "w")
11
+ end
12
+
13
+ accept_header = lambda do |request1, request2|
14
+ request1.headers['Accept'] == request2.headers['Accept']
15
+ end
16
+
17
+ authorization_header = lambda do |request1, request2|
18
+ request1.headers['Authorization'] == request2.headers['Authorization']
19
+ end
20
+
21
+ VCR_OPTS = {
22
+ record: :none, ## this should be :none before pushing
23
+ allow_unused_http_interactions: false,
24
+ match_requests_on: [:method, :uri, :host, :body, accept_header, authorization_header]
25
+ }
26
+
27
+ require 'openstax_exchange'
28
+ require 'lib/openstax/exchange/shared_examples_for_exchange_client_v1'
29
+
30
+ API_VERSION_V1 = 'v1'
31
+
32
+ DEFAULT_CLIENT_PLATFORM_ID = '123'
33
+ DEFAULT_CLIENT_PLATFORM_SECRET = 'abc'
34
+ DEFAULT_CLIENT_SERVER_SCHEME = 'http'
35
+ DEFAULT_CLIENT_SERVER_HOST = 'localhost'
36
+ DEFAULT_CLIENT_SERVER_PORT = 3003
37
+ DEFAULT_CLIENT_SERVER_PATH = nil
38
+ DEFAULT_CLIENT_API_VERSION = API_VERSION_V1
39
+
40
+ def client_server_url(options = {})
41
+ server_scheme = options.fetch(:scheme) { DEFAULT_CLIENT_SERVER_SCHEME }
42
+ server_host = options.fetch(:host) { DEFAULT_CLIENT_SERVER_HOST }
43
+ server_port = options.fetch(:port) { DEFAULT_CLIENT_SERVER_PORT }
44
+ server_path = options.fetch(:path) { DEFAULT_CLIENT_SERVER_PATH }
45
+
46
+ url = URI::Generic.build(
47
+ scheme: server_scheme,
48
+ host: server_host,
49
+ port: server_port,
50
+ path: server_path)
51
+
52
+ url.to_s
39
53
  end