Class: QuickRspec
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- QuickRspec
- Defined in:
- lib/quick-rspec.rb
Constant Summary collapse
- @@coverage =
{}
- @@last_cover =
{}
Class Method Summary collapse
- .collect_stats(example) ⇒ Object
- .load_stats ⇒ Object
- .on_exit ⇒ Object
- .relevant_path(path) ⇒ Object
- .save_stats ⇒ Object
- .start ⇒ Object
- .where_tested(file) ⇒ Object
Class Method Details
.collect_stats(example) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/quick-rspec.rb', line 18 def collect_stats(example) spec = "#{example.metadata[:rerun_file_path]}[#{example.metadata[:scoped_id]}]" root = Rails.root.to_s result = {} cover = Coverage.peek_result cover.each do |path, coverage| next unless path =~ %r{^#{Regexp.escape(root)}\/(app|lib|config)\/.*\.rb}i last_cover = @@last_cover[path] next if coverage == last_cover coverage = coverage.each_with_index.map.map do |count, index| index unless last_cover.present? && count == last_cover[index] end.compact next unless coverage.any? path = QuickRspec.relevant_path(path) result[path] = coverage end @@coverage[spec] = result @@last_cover = cover end |
.load_stats ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/quick-rspec.rb', line 43 def load_stats @@coverage = begin JSON.parse(File.read(Rails.root.join('tmp/quick_rspec.new.json'))) rescue Errno::ENOENT, JSON::ParserError begin JSON.parse(File.read(Rails.root.join('tmp/quick_rspec.json'))) rescue Errno::ENOENT, JSON::ParserError {} end end end |
.on_exit ⇒ Object
84 85 86 |
# File 'lib/quick-rspec.rb', line 84 def on_exit QuickRspec.save_stats end |
.relevant_path(path) ⇒ Object
38 39 40 41 |
# File 'lib/quick-rspec.rb', line 38 def relevant_path(path) path = Rails.root.join(path).to_s path[Rails.root.to_s.length + 1..-1] end |
.save_stats ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/quick-rspec.rb', line 55 def save_stats new_coverage = @@coverage load_stats() new_coverage.each do |spec, coverage| @@coverage[spec] = coverage end dir = Rails.root.join('tmp') FileUtils.mkdir_p(dir) unless File.directory?(dir) File.open(Rails.root.join('tmp/quick_rspec.new.json'), 'w+') do |f| f.write @@coverage.to_json end File.open(Rails.root.join('tmp/quick_rspec.stats'), 'w+') do |f| @@coverage.each do |spec_name, coverage| f.write "#{spec_name}:\n" coverage.each do |path, lines| f.write " #{path}:\n" f.write " #{lines}\n" end end end end |
.start ⇒ Object
14 15 16 |
# File 'lib/quick-rspec.rb', line 14 def start Coverage.start end |
.where_tested(file) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/quick-rspec.rb', line 77 def where_tested(file) @@coverage.map do |spec, coverage| next unless file.in? coverage.keys spec end.compact end |