Class: RSpec::ActiveRecord::CreateRecord
- Includes:
- Matchers::BuiltIn::BaseMatcher::HashFormatting
- Defined in:
- lib/rspec/active_record/create_record.rb
Overview
A matcher
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(scope) ⇒ CreateRecord
constructor
A new instance of CreateRecord.
- #matches?(block) ⇒ Boolean
-
#matching(attributes) ⇒ Object
Make sure that created record matches attributes.
- #once ⇒ Object
- #supports_block_expectations? ⇒ Boolean
- #thrice ⇒ Object
- #times(times) ⇒ Object
- #twice ⇒ Object
Constructor Details
#initialize(scope) ⇒ CreateRecord
Returns a new instance of CreateRecord.
9 10 11 12 |
# File 'lib/rspec/active_record/create_record.rb', line 9 def initialize(scope) @scope = scope super() end |
Instance Method Details
#description ⇒ Object
50 51 52 53 54 55 |
# File 'lib/rspec/active_record/create_record.rb', line 50 def description = "create #{scope_name}" += " #{@times} time#{"s" if @times != 1}" if @times += " matching #{format_hash(@attributes)}" if @attributes improve_hash_formatting end |
#failure_message ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rspec/active_record/create_record.rb', line 57 def failure = "expected to #{description} but" if !match_times? "#{failure} created #{@new_records.size}" else add_diff "#{failure} did not" end end |
#failure_message_when_negated ⇒ Object
66 67 68 |
# File 'lib/rspec/active_record/create_record.rb', line 66 def "expected not to #{description} but did" end |
#matches?(block) ⇒ Boolean
41 42 43 44 45 46 47 48 |
# File 'lib/rspec/active_record/create_record.rb', line 41 def matches?(block) existing_ids = @scope.ids block.call @new_records = @scope.where.not(@scope.primary_key => existing_ids).to_a match_times? && match_attributes? && @new_records.present? end |
#matching(attributes) ⇒ Object
Make sure that created record matches attributes
15 16 17 18 |
# File 'lib/rspec/active_record/create_record.rb', line 15 def matching(attributes) @attributes = attributes self end |
#once ⇒ Object
25 26 27 |
# File 'lib/rspec/active_record/create_record.rb', line 25 def once times(1) end |
#supports_block_expectations? ⇒ Boolean
37 38 39 |
# File 'lib/rspec/active_record/create_record.rb', line 37 def supports_block_expectations? true end |
#thrice ⇒ Object
33 34 35 |
# File 'lib/rspec/active_record/create_record.rb', line 33 def thrice times(3) end |
#times(times) ⇒ Object
20 21 22 23 |
# File 'lib/rspec/active_record/create_record.rb', line 20 def times(times) @times = times self end |
#twice ⇒ Object
29 30 31 |
# File 'lib/rspec/active_record/create_record.rb', line 29 def twice times(2) end |