Module: ChefZero::RSpec::RSpecClassMethods

Included in:
ChefZero::RSpec
Defined in:
lib/chef_zero/rspec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_keyObject

Returns the value of attribute client_key.



9
10
11
# File 'lib/chef_zero/rspec.rb', line 9

def client_key
  @client_key
end

#request_logObject (readonly)

Returns the value of attribute request_log.



10
11
12
# File 'lib/chef_zero/rspec.rb', line 10

def request_log
  @request_log
end

#serverObject

Returns the value of attribute server.



8
9
10
# File 'lib/chef_zero/rspec.rb', line 8

def server
  @server
end

Instance Method Details

#clear_request_logObject



12
13
14
# File 'lib/chef_zero/rspec.rb', line 12

def clear_request_log
  @request_log = []
end

#set_server_options(chef_server_options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chef_zero/rspec.rb', line 16

def set_server_options(chef_server_options)
  if server && chef_server_options != server.options
    server.stop
    self.server = nil
  end

  unless server
    # TODO: can this be logged easily?
    # pp :zero_opts => chef_server_options

    # Set up configuration so that clients will point to the server
    self.server = ChefZero::Server.new(chef_server_options)
    self.client_key = Tempfile.new(["chef_zero_client_key", ".pem"])
    client_key.write(ChefZero::PRIVATE_KEY)
    client_key.close
    # Start the server
    server.start_background
    server.on_response do |request, response|
      request_log << [ request, response ]
    end
  else
    server.clear_data
  end
  clear_request_log
end