Module: WebSocketVCR

Extended by:
WebSocketVCR
Includes:
Errors
Included in:
WebSocketVCR
Defined in:
lib/simple_websocket_vcr.rb,
lib/simple_websocket_vcr/errors.rb,
lib/simple_websocket_vcr/version.rb,
lib/simple_websocket_vcr/cassette.rb,
lib/simple_websocket_vcr/configuration.rb,
lib/simple_websocket_vcr/recordable_websocket_client.rb

Defined Under Namespace

Modules: Errors Classes: Cassette, Configuration, RecordEntry, RecordableWebsocketClient, RecordedJsonSession, RecordedSession, RecordedYamlSession

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cassetteObject

Returns the value of attribute cassette.



13
14
15
# File 'lib/simple_websocket_vcr.rb', line 13

def cassette
  @cassette
end

.cassette=(value) ⇒ Object

Sets the attribute cassette

Parameters:

  • value

    the value to set the attribute cassette to.



13
14
15
# File 'lib/simple_websocket_vcr.rb', line 13

def cassette=(value)
  @cassette = value
end

.configurationObject



50
51
52
# File 'lib/simple_websocket_vcr.rb', line 50

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



46
47
48
# File 'lib/simple_websocket_vcr.rb', line 46

def configure
  yield configuration
end

.disabledObject



54
55
56
# File 'lib/simple_websocket_vcr.rb', line 54

def disabled
  @disabled || false
end

.disabled=(v) ⇒ Object



58
59
60
# File 'lib/simple_websocket_vcr.rb', line 58

def disabled=(v)
  @disabled = v
end

.filename_helper(example, context) ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'lib/simple_websocket_vcr.rb', line 104

def filename_helper(example, context)
  if context.class.[:parent_example_group].nil?
    example_name = example.description.gsub(/\s+/, '_')
    directory = context.class.[:description].gsub(/\s+/, '_')
  else
    example_name = "#{context.class.[:description]}_#{example.description}".gsub(/\s+/, '_')
    directory = context.class.[:parent_example_group][:description].gsub(/\s+/, '_')
  end
  "#{directory}/#{example_name}"
end

.record(example, context, options = {}, &block) ⇒ Object



80
81
82
83
84
# 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_sessionObject



62
63
# File 'lib/simple_websocket_vcr.rb', line 62

def save_session
end

.turn_off!(_options = {}) ⇒ Object



86
87
88
# File 'lib/simple_websocket_vcr.rb', line 86

def turn_off!(_options = {})
  # TODO: impl
end

.turn_on!Object



94
95
96
# File 'lib/simple_websocket_vcr.rb', line 94

def turn_on!
  # TODO: impl
end

.turned_on?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/simple_websocket_vcr.rb', line 90

def turned_on?
  !@cassette.nil?
end

.use_cassette(name, options = {}) ⇒ Object

Use the specified cassette for either recording the real communication or replaying it during the tests.

Parameters:

  • name (String)

    the cassette

  • options (Hash) (defaults to: {})

    options for the cassette

Options Hash (options):

  • :record (Symbol)

    if set to :none there will be no recording; :all means record all the time

  • :erb (Symbol)

    a sub-hash with variables used for ERB substitution in given cassette

  • :reverse_substitution (Boolean)

    if true, the values of :erb hash will be replaced by their names in the cassette. It’s turned-off by default.



72
73
74
75
76
77
78
# 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

Instance Method Details

#live?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/simple_websocket_vcr.rb', line 98

def live?
  @cassette && @cassette.recording?
end

#versionString

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.

Returns the current version.

Returns:

  • (String)

    the current version.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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