Class: Checkend::Testing::FakeClient

Inherits:
Object
  • Object
show all
Defined in:
lib/checkend/testing.rb

Overview

Fake client that captures notices instead of sending them

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ FakeClient

Returns a new instance of FakeClient.



135
136
137
138
# File 'lib/checkend/testing.rb', line 135

def initialize
  @notices = []
  @mutex = Mutex.new
end

Instance Attribute Details

#notices ⇒ Object (readonly)

Returns the value of attribute notices.



133
134
135
# File 'lib/checkend/testing.rb', line 133

def notices
  @notices
end

Instance Method Details

#clear! ⇒ void

This method returns an undefined value.

Clear all captured notices



159
160
161
162
163
# File 'lib/checkend/testing.rb', line 159

def clear!
  @mutex.synchronize do
    @notices.clear
  end
end

#send_notice(notice) ⇒ Hash

Capture a notice instead of sending it

Parameters:

  • notice (Notice) —

    the notice to capture

Returns:

  • (Hash) —

    fake response



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/checkend/testing.rb', line 144

def send_notice(notice)
  @mutex.synchronize do
    @notices << notice
  end

  # Return a fake successful response
  {
    'id' => @notices.size,
    'problem_id' => @notices.size
  }
end