Class: RoxClient::RSpec::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/rox-client-rspec/cache.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cache

Returns a new instance of Cache.



8
9
10
11
# File 'lib/rox-client-rspec/cache.rb', line 8

def initialize options = {}
  @tests = {}
  @workspace, @server_name, @project_api_id = options[:workspace], options[:server_name], options[:project_api_id]
end

Instance Method Details

#known?(test_result) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rox-client-rspec/cache.rb', line 36

def known? test_result
  @tests[@project_api_id] && !!@tests[@project_api_id][test_result.key]
end

#loadObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/rox-client-rspec/cache.rb', line 25

def load
  validate!

  @tests = if File.exists? cache_file
    Oj.load(File.read(cache_file), mode: :strict) rescue {}
  else
    {}
  end
  self
end

#save(test_run) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rox-client-rspec/cache.rb', line 13

def save test_run
  validate!

  @tests = { @project_api_id => @tests[@project_api_id] || {} }
  test_run.results.each{ |r| @tests[@project_api_id][r.key] = test_result_hash(r) }

  FileUtils.mkdir_p File.dirname(cache_file)
  File.open(cache_file, 'w'){ |f| f.write Oj.dump(@tests, mode: :strict) }

  self
end

#stale?(test_result) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rox-client-rspec/cache.rb', line 40

def stale? test_result
  @tests[@project_api_id] && test_result_hash(test_result) != @tests[@project_api_id][test_result.key]
end