module WebSocketVCR

Constants

VERSION

Attributes

cassette[RW]
cassette[RW]

Public Class Methods

configuration() click to toggle source
# File lib/simple_websocket_vcr.rb, line 50
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/simple_websocket_vcr.rb, line 46
def configure
  yield configuration
end
disabled() click to toggle source
# File lib/simple_websocket_vcr.rb, line 54
def disabled
  @disabled || false
end
disabled=(v) click to toggle source
# File lib/simple_websocket_vcr.rb, line 58
def disabled=(v)
  @disabled = v
end
filename_helper(example, context) click to toggle source
# File lib/simple_websocket_vcr.rb, line 104
def filename_helper(example, context)
  if context.class.metadata[:parent_example_group].nil?
    example_name = example.description.gsub(/\s+/, '_')
    directory = context.class.metadata[:description].gsub(/\s+/, '_')
  else
    example_name = "#{context.class.metadata[:description]}_#{example.description}".gsub(/\s+/, '_')
    directory = context.class.metadata[:parent_example_group][:description].gsub(/\s+/, '_')
  end
  "#{directory}/#{example_name}"
end
record(example, context, options = {}, &block) click to toggle source
# File lib/simple_websocket_vcr.rb, line 80
def record(example, context, options = {}, &block)
  fail ArgumentError, '`VCR.record` requires a block.' unless block_given?
  name = filename_helper(example, context)
  use_cassette(name, options, &block)
end
save_session() click to toggle source
# File lib/simple_websocket_vcr.rb, line 62
def save_session
end
turn_off!(_options = {}) click to toggle source
# File lib/simple_websocket_vcr.rb, line 86
def turn_off!(_options = {})
  # TODO: impl
end
turn_on!() click to toggle source
# File lib/simple_websocket_vcr.rb, line 94
def turn_on!
  # TODO: impl
end
turned_on?() click to toggle source
# File lib/simple_websocket_vcr.rb, line 90
def turned_on?
  !@cassette.nil?
end
use_cassette(name, options = {}) { || ... } click to toggle source

Use the specified cassette for either recording the real communication or replaying it during the tests. @param name [String] the cassette @param options [Hash] options for the cassette @option options [Symbol] :record if set to :none there will be no recording; :all means record all the time @option options [Symbol] :erb a sub-hash with variables used for ERB substitution in given cassette @option options [Boolean] :reverse_substitution if true, the values of :erb hash will be replaced by their names in

the cassette. It's turned-off by default.
# File lib/simple_websocket_vcr.rb, line 72
def use_cassette(name, options = {})
  fail ArgumentError, '`VCR.use_cassette` requires a block.' unless block_given?
  self.cassette = Cassette.new(name, options)
  yield
  cassette.save
  self.cassette = nil
end

Public Instance Methods

live?() click to toggle source
# File lib/simple_websocket_vcr.rb, line 98
def live?
  @cassette && @cassette.recording?
end
version() click to toggle source

@return [String] the current version. @note This string also has singleton methods:

* `major` [Integer] The major version.
* `minor` [Integer] The minor version.
* `patch` [Integer] The patch version.
* `parts` [Array<Integer>] List of the version parts.
# File lib/simple_websocket_vcr.rb, line 22
def version
  @version ||= begin
    string = WebSocketVCR::VERSION

    def string.parts
      split('.').map(&:to_i)
    end

    def string.major
      parts[0]
    end

    def string.minor
      parts[1]
    end

    def string.patch
      parts[2]
    end

    string
  end
end

Private Instance Methods

configuration() click to toggle source
# File lib/simple_websocket_vcr.rb, line 50
def configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/simple_websocket_vcr.rb, line 46
def configure
  yield configuration
end
disabled() click to toggle source
# File lib/simple_websocket_vcr.rb, line 54
def disabled
  @disabled || false
end
disabled=(v) click to toggle source
# File lib/simple_websocket_vcr.rb, line 58
def disabled=(v)
  @disabled = v
end
filename_helper(example, context) click to toggle source
# File lib/simple_websocket_vcr.rb, line 104
def filename_helper(example, context)
  if context.class.metadata[:parent_example_group].nil?
    example_name = example.description.gsub(/\s+/, '_')
    directory = context.class.metadata[:description].gsub(/\s+/, '_')
  else
    example_name = "#{context.class.metadata[:description]}_#{example.description}".gsub(/\s+/, '_')
    directory = context.class.metadata[:parent_example_group][:description].gsub(/\s+/, '_')
  end
  "#{directory}/#{example_name}"
end
record(example, context, options = {}, &block) click to toggle source
# File lib/simple_websocket_vcr.rb, line 80
def record(example, context, options = {}, &block)
  fail ArgumentError, '`VCR.record` requires a block.' unless block_given?
  name = filename_helper(example, context)
  use_cassette(name, options, &block)
end
save_session() click to toggle source
# File lib/simple_websocket_vcr.rb, line 62
def save_session
end
turn_off!(_options = {}) click to toggle source
# File lib/simple_websocket_vcr.rb, line 86
def turn_off!(_options = {})
  # TODO: impl
end
turn_on!() click to toggle source
# File lib/simple_websocket_vcr.rb, line 94
def turn_on!
  # TODO: impl
end
turned_on?() click to toggle source
# File lib/simple_websocket_vcr.rb, line 90
def turned_on?
  !@cassette.nil?
end
use_cassette(name, options = {}) { || ... } click to toggle source

Use the specified cassette for either recording the real communication or replaying it during the tests. @param name [String] the cassette @param options [Hash] options for the cassette @option options [Symbol] :record if set to :none there will be no recording; :all means record all the time @option options [Symbol] :erb a sub-hash with variables used for ERB substitution in given cassette @option options [Boolean] :reverse_substitution if true, the values of :erb hash will be replaced by their names in

the cassette. It's turned-off by default.
# File lib/simple_websocket_vcr.rb, line 72
def use_cassette(name, options = {})
  fail ArgumentError, '`VCR.use_cassette` requires a block.' unless block_given?
  self.cassette = Cassette.new(name, options)
  yield
  cassette.save
  self.cassette = nil
end