Class: SwissKnife::RSpec::Matchers::Allow
- Inherits:
-
Object
- Object
- SwissKnife::RSpec::Matchers::Allow
- Defined in:
- lib/swiss_knife/rspec/allow.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
Returns the value of attribute attribute.
-
#failed ⇒ Object
Returns the value of attribute failed.
-
#record ⇒ Object
Returns the value of attribute record.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #description ⇒ Object
- #does_not_match?(record) ⇒ Boolean
- #failure_message ⇒ Object
- #for(attribute) ⇒ Object
-
#initialize(values) ⇒ Allow
constructor
A new instance of Allow.
- #matches?(record) ⇒ Boolean
- #matches_against?(compare) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(values) ⇒ Allow
Returns a new instance of Allow.
11 12 13 14 |
# File 'lib/swiss_knife/rspec/allow.rb', line 11 def initialize(values) @failed = [] @values = values end |
Instance Attribute Details
#attribute ⇒ Object
Returns the value of attribute attribute.
9 10 11 |
# File 'lib/swiss_knife/rspec/allow.rb', line 9 def attribute @attribute end |
#failed ⇒ Object
Returns the value of attribute failed.
9 10 11 |
# File 'lib/swiss_knife/rspec/allow.rb', line 9 def failed @failed end |
#record ⇒ Object
Returns the value of attribute record.
9 10 11 |
# File 'lib/swiss_knife/rspec/allow.rb', line 9 def record @record end |
#values ⇒ Object
Returns the value of attribute values.
9 10 11 |
# File 'lib/swiss_knife/rspec/allow.rb', line 9 def values @values end |
Instance Method Details
#description ⇒ Object
26 27 28 |
# File 'lib/swiss_knife/rspec/allow.rb', line 26 def description "allow #{values.inspect} as #{attribute}" end |
#does_not_match?(record) ⇒ Boolean
21 22 23 24 |
# File 'lib/swiss_knife/rspec/allow.rb', line 21 def does_not_match?(record) @record = record matches_against?(true) end |
#failure_message ⇒ Object
30 31 32 |
# File 'lib/swiss_knife/rspec/allow.rb', line 30 def "expected #{record.inspect} to allow each of #{values.inspect} as #{attribute.inspect} value (didn't accept #{failed.inspect})" end |
#for(attribute) ⇒ Object
38 39 40 41 |
# File 'lib/swiss_knife/rspec/allow.rb', line 38 def for(attribute) @attribute = attribute self end |
#matches?(record) ⇒ Boolean
16 17 18 19 |
# File 'lib/swiss_knife/rspec/allow.rb', line 16 def matches?(record) @record = record matches_against?(false) end |
#matches_against?(compare) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/swiss_knife/rspec/allow.rb', line 43 def matches_against?(compare) raise "The allow matcher requires an attribute; use subject.should allow(*values).as(attribute)" unless attribute values.each do |value| record.__send__("#{attribute}=", value) record.valid? failed << value if record.errors[attribute].empty? == compare end failed.empty? end |
#negative_failure_message ⇒ Object
34 35 36 |
# File 'lib/swiss_knife/rspec/allow.rb', line 34 def "expected #{record.inspect} to reject each of #{values.inspect} as #{attribute.inspect} value (accepted #{failed.inspect})" end |