Skip to content

Commit 069a66f

Browse files
committed
tests add to a counter instead of printing to output
1 parent 051b9ce commit 069a66f

File tree

4 files changed

+44
-26
lines changed

4 files changed

+44
-26
lines changed

spec/controllers/scim_rails/scim_resource_controller_spec.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
RSpec.describe ScimRails::ScimResourceController, type: :controller do
44
include AuthHelper
5+
include CallbackHelper
6+
7+
let!(:counter) { CallbackHelper::CallbackCounter.new }
58

69
routes { ScimRails::Engine.routes }
710

@@ -58,7 +61,7 @@
5861
context "when before_scim_response is defined" do
5962
before do
6063
ScimRails.config.before_scim_response = lambda do |body|
61-
print "#{body}"
64+
counter.before.call
6265
end
6366
end
6467

@@ -67,16 +70,14 @@
6770
end
6871

6972
it "successfully calls before_scim_response" do
70-
get :resource_user
71-
72-
expect{ get :resource_user }.to output("#{request.params}").to_stdout
73+
expect{ get :resource_user }.to change{ counter.count }.from(0).to(1)
7374
end
7475
end
7576

7677
context "when after_scim_response is defined" do
7778
before do
7879
ScimRails.config.after_scim_response = lambda do |object, status|
79-
print "#{object} #{status}"
80+
counter.after.call
8081
end
8182
end
8283

@@ -85,9 +86,7 @@
8586
end
8687

8788
it "successfully calls before_scim_response" do
88-
get :resource_user
89-
90-
expect{ get :resource_user }.to output("#{ScimRails.config.resource_user_schema} RETRIEVED").to_stdout
89+
expect{ get :resource_user }.to change{ counter.count }.from(0).to(2)
9190
end
9291
end
9392
end
@@ -146,7 +145,7 @@
146145
context "when before_scim_response is defined" do
147146
before do
148147
ScimRails.config.before_scim_response = lambda do |body|
149-
print "#{body}"
148+
counter.before.call
150149
end
151150
end
152151

@@ -155,16 +154,14 @@
155154
end
156155

157156
it "successfully calls before_scim_response" do
158-
get :resource_group
159-
160-
expect{ get :resource_group }.to output("#{request.params}").to_stdout
157+
expect{ get :resource_group }.to change{ counter.count }.from(0).to(1)
161158
end
162159
end
163160

164161
context "when after_scim_response is defined" do
165162
before do
166163
ScimRails.config.after_scim_response = lambda do |object, status|
167-
print "#{object} #{status}"
164+
counter.after.call
168165
end
169166
end
170167

@@ -173,7 +170,7 @@
173170
end
174171

175172
it "successfully calls before_scim_response" do
176-
expect{ get :resource_group }.to output("#{ScimRails.config.resource_group_schema} RETRIEVED").to_stdout
173+
expect{ get :resource_group }.to change{ counter.count }.from(0).to(2)
177174
end
178175
end
179176
end

spec/controllers/scim_rails/scim_schema_controller_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module ScimRails
44
RSpec.describe ScimSchemaController, type: :controller do
55
include AuthHelper
6+
include CallbackHelper
7+
68
routes { ScimRails::Engine.routes }
79

810
describe "get_schema" do
@@ -32,6 +34,8 @@ module ScimRails
3234

3335
context "when authorized" do
3436
let(:body) { JSON.parse(response.body) }
37+
38+
let!(:counter) { CallbackHelper::CallbackCounter.new }
3539

3640
before :each do
3741
http_login(company)
@@ -64,7 +68,7 @@ module ScimRails
6468
context "when before_scim_response is defined" do
6569
before do
6670
ScimRails.config.before_scim_response = lambda do |body|
67-
print "#{body}"
71+
counter.before.call
6872
end
6973
end
7074

@@ -73,16 +77,14 @@ module ScimRails
7377
end
7478

7579
it "successfully calls before_scim_response" do
76-
get :get_schema, params: { id: 1 }
77-
78-
expect{ get :get_schema, params: { id: 1 } }.to output("#{request.params}").to_stdout
80+
expect{ get :get_schema, params: { id: 1 } }.to change{ counter.count }.from(0).to(1)
7981
end
8082
end
8183

8284
context "when after_scim_response is defined" do
8385
before do
8486
ScimRails.config.after_scim_response = lambda do |object, status|
85-
print "#{object} #{status}"
87+
counter.after.call
8688
end
8789
end
8890

@@ -91,7 +93,7 @@ module ScimRails
9193
end
9294

9395
it "successfully calls after_scim_response" do
94-
expect{ get :get_schema, params: { id: 1 } }.to output("#{{}} RETRIEVED").to_stdout
96+
expect{ get :get_schema, params: { id: 1 } }.to change{ counter.count }.from(0).to(2)
9597
end
9698
end
9799
end

spec/controllers/scim_rails/scim_service_controller_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
RSpec.describe ScimRails::ScimServiceController, type: :controller do
44
include AuthHelper
5+
include CallbackHelper
56

67
routes { ScimRails::Engine.routes }
78

@@ -33,6 +34,8 @@
3334
context "when authorized" do
3435
let(:body) { JSON.parse(response.body) }
3536

37+
let!(:counter) { CallbackHelper::CallbackCounter.new }
38+
3639
before :each do
3740
http_login(company)
3841
end
@@ -58,7 +61,7 @@
5861
context "when before_scim_response is defined" do
5962
before do
6063
ScimRails.config.before_scim_response = lambda do |body|
61-
print "#{body}"
64+
counter.before.call
6265
end
6366
end
6467

@@ -67,16 +70,14 @@
6770
end
6871

6972
it "successfully calls before_scim_response" do
70-
get :configuration
71-
72-
expect{ get :configuration }.to output("#{request.params}").to_stdout
73+
expect{ get :configuration }.to change{ counter.count }.from(0).to(1)
7374
end
7475
end
7576

7677
context "when after_scim_response is defined" do
7778
before do
7879
ScimRails.config.after_scim_response = lambda do |object, status|
79-
print "#{object} #{status}"
80+
counter.after.call
8081
end
8182
end
8283

@@ -85,7 +86,7 @@
8586
end
8687

8788
it "successfully calls after_scim_response" do
88-
expect{ get :configuration }.to output("#{ScimRails.config.config_schema} RETRIEVED").to_stdout
89+
expect{ get :configuration }.to change{ counter.count }.from(0).to(2)
8990
end
9091
end
9192
end

spec/support/callback_helper.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module CallbackHelper
2+
class CallbackCounter
3+
attr_reader :count
4+
attr_accessor :before, :after
5+
6+
def initialize
7+
@count = 0
8+
9+
@before = lambda do
10+
@count += 1
11+
end
12+
13+
@after = lambda do
14+
@count += 2
15+
end
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)