module WebSocketVCR
Constants
- VERSION
Attributes
Public Class Methods
# File lib/simple_websocket_vcr.rb, line 50 def configuration @configuration ||= Configuration.new end
# File lib/simple_websocket_vcr.rb, line 46 def configure yield configuration end
# File lib/simple_websocket_vcr.rb, line 54 def disabled @disabled || false end
# File lib/simple_websocket_vcr.rb, line 58 def disabled=(v) @disabled = v end
# 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
# 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
# File lib/simple_websocket_vcr.rb, line 62 def save_session end
# File lib/simple_websocket_vcr.rb, line 86 def turn_off!(_options = {}) # TODO: impl end
# File lib/simple_websocket_vcr.rb, line 94 def turn_on! # TODO: impl end
# File lib/simple_websocket_vcr.rb, line 90 def turned_on? !@cassette.nil? end
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
# File lib/simple_websocket_vcr.rb, line 98 def live? @cassette && @cassette.recording? end
@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
# File lib/simple_websocket_vcr.rb, line 50 def configuration @configuration ||= Configuration.new end
# File lib/simple_websocket_vcr.rb, line 46 def configure yield configuration end
# File lib/simple_websocket_vcr.rb, line 54 def disabled @disabled || false end
# File lib/simple_websocket_vcr.rb, line 58 def disabled=(v) @disabled = v end
# 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
# 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
# File lib/simple_websocket_vcr.rb, line 62 def save_session end
# File lib/simple_websocket_vcr.rb, line 86 def turn_off!(_options = {}) # TODO: impl end
# File lib/simple_websocket_vcr.rb, line 94 def turn_on! # TODO: impl end
# File lib/simple_websocket_vcr.rb, line 90 def turned_on? !@cassette.nil? end
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