Class: Rspec::Rotten::ExampleStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/rotten/example_store.rb

Constant Summary collapse

ROTTEN_DURATION =

1 year duration when AS is not available

Time.parse("2016-01-01") - Time.parse("2015-01-01")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExampleStore

Returns a new instance of ExampleStore.



14
15
16
17
# File 'lib/rspec/rotten/example_store.rb', line 14

def initialize()
  @file_path = Rspec::Rotten::Configuration.results_file
  @records = File.exists?(@file_path) ? JSON.parse(read_example_data) : []
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

#recordsObject

Returns the value of attribute records.



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

def records
  @records
end

Instance Method Details

#delete(example) ⇒ Object



23
24
25
# File 'lib/rspec/rotten/example_store.rb', line 23

def delete(example)
  @records.delete example
end

#find(example) ⇒ Object



19
20
21
# File 'lib/rspec/rotten/example_store.rb', line 19

def find(example)
  @records.find{ |x| x['id'] == example.id }
end

#notify_rottenObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspec/rotten/example_store.rb', line 40

def notify_rotten
  if @rotten.any?
    @message = %Q{
    \n\nYou have #{@rotten.count} specs that haven't failed for extended period of time.\n\t
    \n\nYou may want to consider removing them:\n\t
    #{@records.map {|example| example['description'] + " - " + example['location'] }.join("\n\t")}
    \n
    }
    RSpec::Core::Formatters::ConsoleCodes.wrap(@message, :pending)
  end
end

#rottenObject

use config for date



35
36
37
38
# File 'lib/rspec/rotten/example_store.rb', line 35

def rotten
  rotten_duration = Rspec::Rotten::Configuration.time_to_rotten || ROTTEN_TIME
  @rotten ||= @records.select {|x| !x['date'].nil? && x['date'] < Time.now() - rotten_duration }
end

#saveObject



27
28
29
30
31
32
# File 'lib/rspec/rotten/example_store.rb', line 27

def save
  f = File.open(@file_path,"w")
  f.truncate(0)
  f.write(@records.to_json)
  f.close
end