simplecov-tdd 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: eecc7193441832d9a0fa36b2cbad35da148fba17
4
- data.tar.gz: 2b6bc9c591fe4ffc4fa11b9951d015ed624e7e56
2
+ SHA256:
3
+ metadata.gz: 678d4521b0050e2b500bf036c4e32031352bc1fa00ab8f2a9aecb7cd2125febd
4
+ data.tar.gz: 33b54df0fd182be3c66bd5bbc9131c4414ba6c158d4381c9959bcd4edd593203
5
5
  SHA512:
6
- metadata.gz: b146adda2629ee2f253bf2dcc191882b66078d43096bb6ac62f25a79fc394b2d33bf80cf299e0523145a8ca8b2bf31b1874283472a3adf9d9763bf53fe70b29c
7
- data.tar.gz: 1fa2334a1d6733c1c4a30a1f74843087ac26fab6b90a83d770ee8814db4b9d5ee8da0a03b04dec49db5f82fd9e72aa7aeb20147ab53f2c2669cb0bef288ce5c6
6
+ metadata.gz: b08b96e78e4b3ae6aeceb124513e52fb2527394d50cde2858db863b8fb75c9eddb8142942784c12c81931359b256f7d1c815f6b3feab8f80209c95603ad5eeef
7
+ data.tar.gz: 48a4a28e253328074c0a2e05fe616d064e2257af0090830cbd760d44a27dc831e303739a722dad5308536987752057c9be4031fd93d2bfbcaf3947ed19b7480c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ 0.2.0 (2019-03-06)
2
+ ==================
3
+ ## Features
4
+ * Added style_output configuration option. There are two options: [:simple, :verbose].
5
+ :simple is the default, while :verbose outputs line numbers along with source code that
6
+ is missing coverage.
7
+ * Added debug_mode configuration option for investigating mismatched filenames. Default is disabled
8
+
9
+ ## Improvements
10
+ * Improved output of the current tested file to start with the app/ directory instead
11
+ of full path
12
+ * Slight optimizations done to the way the current filename is detected
13
+ * Better documentation added
14
+
15
+ ## Bug fixes
16
+ * Files previously containing the phrase 'spec' as part of their name would be
17
+ improperly formatted. This caused these files to come up as mismatches.
18
+
1
19
  0.1.0 (2019-02-20)
2
20
  ==================
3
21
  ## Features
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Simplecov::Tdd
2
2
 
3
- A SimpleCov formatter for test driven development
3
+ A SimpleCov formatter for test driven development. Displays code coverage results in the console for single files
4
+
5
+ ![Example TDD](https://github.com/joshmfrankel/simplecov-tdd/blob/master/example.gif)
4
6
 
5
7
  ## Installation
6
8
 
@@ -21,15 +23,72 @@ Or install it yourself as:
21
23
  ## Usage
22
24
 
23
25
  1. Ensure that you've configured your project to SimpleCov's _Getting Started_ section: https://github.com/colszowka/simplecov#getting-started
24
- 2. Set your `SimpleCov.formatter` to the following:
26
+ 2. Set your SimpleCov configuration to the following:
25
27
 
26
28
  ```ruby
29
+ require "simplecov/tdd"
27
30
  SimpleCov.formatter = Simplecov::Formatter::Tdd
31
+ # OR use multi-formatter
32
+ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
33
+ SimpleCov::Formatter::HTMLFormatter,
34
+ Simplecov::Formatter::Tdd
35
+ ])
36
+ ```
37
+
38
+ Simple Setup:
39
+
40
+ ```ruby
41
+ # /spec/spec_helper.rb
42
+ require "simplecov"
43
+ require "simplecov/tdd"
44
+ SimpleCov.formatter = SimpleCov::Formatter::Tdd
45
+ SimpleCov.start 'rails'
28
46
  ```
29
- 3. Run your tests using rspec path/to/file_spec.rb or guard
47
+
48
+ 3. Run your tests using `rspec path/to/file_spec.rb` or `guard`
30
49
  4. Fix the missing coverage
31
50
  5. 💰 Profit! 💰
32
51
 
52
+ ## Configuration options
53
+
54
+ There are a few configuration options that may be set before formatting is called.
55
+ Generally you may place these after `SimpleCov.formatter` or `SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new` in your setup.
56
+
57
+ ### output_style (default: :simple)
58
+ When there are lines missing coverage, this option determines how to display output.
59
+ The accepted values are `:simple` (default) or `:verbose`.
60
+
61
+ ```ruby
62
+ SimpleCov::Formatter::Tdd.output_style = :verbose
63
+ ```
64
+
65
+ Here's an example of what :verbose output looks like:
66
+
67
+ ```ruby
68
+ app/models/matched_90.rb
69
+ 90.0% coverage, 167 total lines
70
+
71
+ The following 2 lines have missing coverage:
72
+ [5, 25]
73
+
74
+ line | source code
75
+ -------------------
76
+ 5 => obj.is_a?(SomeClass)
77
+ 25 => SomeClass.explode!
78
+ ```
79
+
80
+ ### debug_mode (default: false)
81
+ This is useful for determining if the current file being tested doesn't have
82
+ a match from SimpleCov's file list.
83
+
84
+ ```ruby
85
+ SimpleCov::Formatter::Tdd.debug_mode = true
86
+ ```
87
+
88
+ ## Future Features
89
+
90
+ * Support for minitest
91
+
33
92
  ## Development
34
93
 
35
94
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/example.gif ADDED
Binary file
data/lib/simplecov/tdd.rb CHANGED
@@ -3,51 +3,91 @@ require "simplecov/tdd/version"
3
3
 
4
4
  module SimpleCov
5
5
  module Formatter
6
+
7
+ # A SimpleCov formatter for generating single file results while using
8
+ # test driven development principles
6
9
  class Tdd
7
10
  attr_reader :result
8
11
 
9
- def format(coverage_results, debug: false)
12
+ # Hook into SimpleCov format by defining specific implementation
13
+ # of #format for the TDD formatter
14
+ def format(coverage_results)
10
15
  @result = single_result(coverage_results)
11
16
 
17
+ # Is there a matching result?
12
18
  if result.nil?
13
- raise StandardError, "Could not find #{current_filename} as part of the SimpleCov::FileList results" if debug
14
- return
19
+ raise StandardError, "Could not find #{current_filename} as part of the SimpleCov::FileList results" if debug_mode
20
+ return # Early return silently dies outside of debug mode
15
21
  end
16
22
 
17
- puts current_filename
18
- coverage_overview_text
19
- missed_line_numbers_message
23
+ puts format_filename_for_output
24
+ puts coverage_overview_text
25
+ puts missed_line_numbers_message
26
+ end
27
+
28
+ # Class level attr_writer
29
+ # @param style [Symbol] the symbol representation of the output_style
30
+ # accepted values are: [:simple, :verbose]
31
+ def self.output_style=(style)
32
+ @output_style = style
33
+ end
34
+
35
+ # Class level attr_reader
36
+ def self.output_style
37
+ @output_style
38
+ end
39
+
40
+ # Instance level method that defers to class_level variable when
41
+ # set via configuration. The default output_style is :simple
42
+ def output_style
43
+ self.class.output_style || :simple
44
+ end
45
+
46
+ # Class level attr_writer
47
+ # @param flag [Boolean] the current status (true/false) of debug mode
48
+ def self.debug_mode=(flag)
49
+ @debug_mode = flag
50
+ end
51
+
52
+ # Class level attr_reader
53
+ def self.debug_mode
54
+ @debug_mode
55
+ end
56
+
57
+ # Instance level method that defers to class_level variable when
58
+ # set via configuration. The default debug_mode is false
59
+ def debug_mode
60
+ self.class.debug_mode || false
20
61
  end
21
62
 
22
63
  private
23
64
 
24
- # From SimpleCov::FileList match the current_filename to a corresponding
25
- # coverage result
65
+ # Match the current file against the SimpleCov::FileList results to determine
66
+ # a matching test
67
+ # @param coverage_results [SimpleCov::Result] the incoming results from running
68
+ # SimpleCov after tests
26
69
  def single_result(coverage_results)
27
- coverage_results.files.select { |file| file.filename == current_filename }[0]
70
+ coverage_results.files.detect { |file| file.filename == current_filename }
28
71
  end
29
72
 
30
73
  # Infer the current_filename based on incoming ARGV command line
31
74
  # arguments and a matching spec type file
32
75
  def current_filename
33
76
  @_current_filename ||= begin
34
- # @todo Can we hook into Guard watched file? That would be more accurate
35
77
  # @TODO support for minitest
36
-
37
- argument_index = nil
38
- ARGV.each.with_index do |arg, index|
39
- if arg.match(/_spec.rb/)
40
- argument_index = index
41
- break
42
- end
43
- end
78
+ argument_index = ARGV.find_index { |arg| arg.match(/_spec.rb/) }
44
79
 
45
80
  if argument_index
46
- Dir.pwd + "/" + ARGV[argument_index].sub("spec", "app").sub("_spec", "")
81
+ Dir.pwd + "/" + ARGV[argument_index].sub("spec/", "app/").sub("_spec.rb", ".rb")
47
82
  end
48
83
  end
49
84
  end
50
85
 
86
+ # Format the currently matched filename to be more human readable
87
+ def format_filename_for_output
88
+ "app/" + current_filename.split("/app/")[1]
89
+ end
90
+
51
91
  # @todo tty support for colors
52
92
  def coverage_overview_text
53
93
  covered_percent = result.covered_percent.round(2)
@@ -67,13 +107,28 @@ module SimpleCov
67
107
  end
68
108
  end
69
109
 
70
- puts colorized_overview_text
110
+ colorized_overview_text
71
111
  end
72
112
 
113
+ # Display the missing line numbers in a summary message
73
114
  def missed_line_numbers_message
74
115
  return if result.covered_percent == 100
75
116
 
76
- puts "\nThe following #{missed_line_numbers.size} lines have missing coverage: \n\e[31m#{missed_line_numbers}\e[0m"
117
+ "\nThe following #{missed_line_numbers.size} lines have missing coverage: \n\e[31m#{missed_line_numbers}\e[0m".tap do |output|
118
+ output << missed_line_numbers_verbose_message
119
+ end
120
+ end
121
+
122
+ # When output_style == :verbose, display a table that includes the
123
+ # line number missing converage as well as the related code
124
+ def missed_line_numbers_verbose_message
125
+ return "" if output_style != :verbose
126
+
127
+ "\nline | source code\n-------------------\n".tap do |output|
128
+ result.missed_lines.each do |missed_line|
129
+ output << missed_line.line_number.to_s + " => " + missed_line.src.strip + "\n"
130
+ end
131
+ end
77
132
  end
78
133
 
79
134
  def missed_line_numbers
@@ -1,5 +1,5 @@
1
1
  module SimpleCov
2
2
  module Tdd
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov-tdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Frankel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-21 00:00:00.000000000 Z
11
+ date: 2019-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -99,6 +99,7 @@ files:
99
99
  - Rakefile
100
100
  - bin/console
101
101
  - bin/setup
102
+ - example.gif
102
103
  - lib/simplecov/tdd.rb
103
104
  - lib/simplecov/tdd/version.rb
104
105
  - simplecov-tdd.gemspec
@@ -120,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
121
  - !ruby/object:Gem::Version
121
122
  version: '0'
122
123
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.6.13
124
+ rubygems_version: 3.0.3
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: SimpleCov formatter for test driven development