module GCR
Constants
- ConfigError
- Error
- NoRecording
- RunningError
Public Instance Methods
cassette()
click to toggle source
# File lib/gcr.rb, line 77 def cassette @cassette end
cassette_dir()
click to toggle source
Where GCR
stores cassettes.
Returns a String path to a directory. Raises ConfigError
if not configured.
# File lib/gcr.rb, line 38 def cassette_dir @cassette_dir || (raise ConfigError, "no cassette dir configured") end
cassette_dir=(path)
click to toggle source
Specify where GCR
should store cassettes.
path - The String path to a directory.
Returns nothing.
# File lib/gcr.rb, line 30 def cassette_dir=(path) raise RunningError, "cannot configure GCR within #with_cassette block" if @running @cassette_dir = path end
ignore(*fields)
click to toggle source
Ignore these fields when matching requests.
*fields - String field names (eg. “token”).
Returns nothing.
# File lib/gcr.rb, line 14 def ignore(*fields) ignored_fields.concat(fields.map(&:to_s)) end
ignored_fields()
click to toggle source
Fields that are ignored when matching requests.
Returns an Array of Strings.
# File lib/gcr.rb, line 21 def ignored_fields @ignored_fields ||= [] end
insert(name)
click to toggle source
# File lib/gcr.rb, line 59 def insert(name) @cassette = Cassette.new(name) if @cassette.exist? @cassette.start_playing else @cassette.start_recording end end
remove()
click to toggle source
# File lib/gcr.rb, line 68 def remove if @cassette.exist? @cassette.stop_playing else @cassette.stop_recording end @cassette = nil end
stub()
click to toggle source
The stub that is being mocked.
Returns a A GRPC::ClientStub instance. Raises ConfigError
if not configured.
# File lib/gcr.rb, line 55 def stub @stub || (raise ConfigError, "no stub configured") end
stub=(stub)
click to toggle source
Specify the stub to intercept calls to.
stub - A GRPC::ClientStub instance.
Returns nothing.
# File lib/gcr.rb, line 47 def stub=(stub) raise RunningError, "cannot configure GCR within #with_cassette block" if @running @stub = stub end
with_cassette(name, &blk)
click to toggle source
If a cassette with the given name exists, play that cassette for the provided block. Otherwise, record a cassette with the provided block.
Returns nothing.
# File lib/gcr.rb, line 85 def with_cassette(name, &blk) @cassette = Cassette.new(name) if @cassette.exist? @cassette.play(&blk) else @cassette.record(&blk) end ensure @cassette = nil end