Module: CapybaraMock
- Defined in:
- lib/capybara_mock.rb,
lib/capybara_mock/stub.rb,
lib/capybara_mock/version.rb,
lib/capybara_mock/interceptor/base.rb,
lib/capybara_mock/interceptor/cuprite.rb
Overview
## CapybaraMock
Mock capybara browser http requests.
Defined Under Namespace
Modules: Interceptor Classes: Error, Stub
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.clear_stubs ⇒ Object
Clear all current session stubs.
-
.remove_stub(stub) ⇒ Object
Remove capybara stub from current session.
-
.reset! ⇒ Object
Reset capybara mock interceptor.
-
.save_unstubbed_requests(path) ⇒ Object
Save unstubbed requests to path.
-
.stub_path(method, path, &block) ⇒ CapybaraMock::Stub
Stub capybara request for current session using path.
-
.stub_request(method, url, &block) ⇒ CapybaraMock::Stub
Stub capybara request for current session using url.
Class Method Details
.clear_stubs ⇒ Object
Clear all current session stubs
89 90 91 |
# File 'lib/capybara_mock.rb', line 89 def clear_stubs interceptor.stubs.clear end |
.remove_stub(stub) ⇒ Object
Remove capybara stub from current session.
84 85 86 |
# File 'lib/capybara_mock.rb', line 84 def remove_stub(stub) interceptor.stubs.delete(stub) end |
.reset! ⇒ Object
Reset capybara mock interceptor.
112 113 114 |
# File 'lib/capybara_mock.rb', line 112 def reset! @interceptor = nil end |
.save_unstubbed_requests(path) ⇒ Object
Save unstubbed requests to path.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/capybara_mock.rb', line 94 def save_unstubbed_requests(path) return false unless @interceptor && @interceptor.unstubbed_requests.present? File.open(path, 'w') do |f| @interceptor.unstubbed_requests.each do |request| f.puts "#{request[:method]} #{request[:url]} #{request[:query]}" request[:headers].each do |k, v| f.puts "#{k}: #{v}" end f.puts request[:body] f.puts end end true end |
.stub_path(method, path, &block) ⇒ CapybaraMock::Stub
Stub capybara request for current session using path.
64 65 66 67 |
# File 'lib/capybara_mock.rb', line 64 def stub_path(method, path, &block) url = File.join(.server.base_url, path) stub_request(method, url, &block) end |
.stub_request(method, url, &block) ⇒ CapybaraMock::Stub
Stub capybara request for current session using url. It also initialize interceptor for current session on first stub.
75 76 77 78 79 |
# File 'lib/capybara_mock.rb', line 75 def stub_request(method, url, &block) Stub.new(method, url, &block).tap do |stub| interceptor.stubs << stub end end |