Class: RspecShnork::RspecShnork
- Inherits:
-
Object
- Object
- RspecShnork::RspecShnork
- Defined in:
- lib/rspec_shnork_matchers.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(thresholds, path = nil) ⇒ RspecShnork
constructor
A new instance of RspecShnork.
- #matches?(target) ⇒ Boolean
- #messages_for(error) ⇒ Object
- #messages_to_string(error) ⇒ Object
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(thresholds, path = nil) ⇒ RspecShnork
Returns a new instance of RspecShnork.
13 14 15 16 |
# File 'lib/rspec_shnork_matchers.rb', line 13 def initialize thresholds, path = nil @path = path || '/' @thresholds = thresholds end |
Instance Method Details
#failure_message ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rspec_shnork_matchers.rb', line 23 def = 5 msg = <<-EOM Shnork found #{(404)} and #{(500)}. One or both of these are over the accepted thresholds (404 -> #{@thresholds[404]}, 500 -> #{@thresholds[500]}). EOM [404, 500].each do |error| i = 0 if (error) > 0 then show_errors = (error) < ? (error) : msg += " First #{show_errors} discovered #{error} error#{ show_errors == 1 ? '' : 's'}:\n" while i < and i < (error) msg += " * " + @results.codes[error][i] + "\n" i += 1 end end end return msg end |
#matches?(target) ⇒ Boolean
18 19 20 21 |
# File 'lib/rspec_shnork_matchers.rb', line 18 def matches?(target) @results = Shnork::Hunt(@path) (404) <= @thresholds[404] and (500) <= @thresholds[500] end |
#messages_for(error) ⇒ Object
43 44 45 46 |
# File 'lib/rspec_shnork_matchers.rb', line 43 def (error) return 0 unless @results.codes.has_key? error return @results.codes[error].size end |
#messages_to_string(error) ⇒ Object
48 49 50 51 |
# File 'lib/rspec_shnork_matchers.rb', line 48 def (error) err = ((error) == 1) ? "error" : "errors" "#{(error)} #{error} #{err}" end |
#negative_failure_message ⇒ Object
53 54 55 |
# File 'lib/rspec_shnork_matchers.rb', line 53 def "expected shnork not to pass" end |