Class: Rspec::Rotten::ExampleStore
- Inherits:
-
Object
- Object
- Rspec::Rotten::ExampleStore
- 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
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
- #delete(example) ⇒ Object
- #find(example) ⇒ Object
-
#initialize ⇒ ExampleStore
constructor
A new instance of ExampleStore.
- #notify_rotten ⇒ Object
-
#rotten ⇒ Object
use config for date.
- #save ⇒ Object
Constructor Details
#initialize ⇒ ExampleStore
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_path ⇒ Object
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 |
#records ⇒ Object
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_rotten ⇒ Object
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 |
#rotten ⇒ Object
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 |
#save ⇒ Object
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 |