Sha256: 3e16ef62ea48eee02335452531859919f594d96a141f5040db8664e041d30b02
Contents?: true
Size: 1.92 KB
Versions: 3
Compression:
Stored size: 1.92 KB
Contents
class Tally attr_accessor :files, :examples, :expectations, :failures, :errors def initialize @files = @examples = @expectations = @failures = @errors = 0 end def files!(add=1) @files += add end def examples!(add=1) @examples += add end def expectations!(add=1) @expectations += add end def failures!(add=1) @failures += add end def errors!(add=1) @errors += add end def file pluralize files, "file" end def example pluralize examples, "example" end def expectation pluralize expectations, "expectation" end def failure pluralize failures, "failure" end def error pluralize errors, "error" end def format [ file, example, expectation, failure, error ].join(", ") end alias_method :to_s, :format def pluralize(count, singular) "#{count} #{singular}#{'s' unless count == 1}" end private :pluralize end class TallyAction attr_reader :counter def initialize @counter = Tally.new end def register MSpec.register :load, self MSpec.register :exception, self MSpec.register :example, self MSpec.register :expectation, self end def unregister MSpec.unregister :load, self MSpec.unregister :exception, self MSpec.unregister :example, self MSpec.unregister :expectation, self end def load @counter.files! end # Callback for the MSpec :expectation event. Increments the # tally of expectations (e.g. #should, #should_receive, etc.). def expectation(state) @counter.expectations! end # Callback for the MSpec :exception event. Increments the # tally of errors and failures. def exception(exception) exception.failure? ? @counter.failures! : @counter.errors! end # Callback for the MSpec :example event. Increments the tally # of examples. def example(state, block) @counter.examples! end def format @counter.format end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mspec-1.5.8 | lib/mspec/runner/actions/tally.rb |
mspec-1.5.7 | lib/mspec/runner/actions/tally.rb |
mspec-1.5.9 | lib/mspec/runner/actions/tally.rb |