Class: RSpec::TagMatchers::HasDateSelect
- Inherits:
-
MultipleInputMatcher
- Object
- MultipleInputMatcher
- RSpec::TagMatchers::HasDateSelect
- Defined in:
- lib/rspec/tag_matchers/has_date_select.rb
Overview
A matcher that matches Rails’ date_select
drop-downs.
Instance Method Summary collapse
-
#description ⇒ String
Returns a description of the matcher’s criteria.
-
#discard(*parts) ⇒ HasDateSelect
Specifies that one or more components of the date will be hidden by Rails’
date_select
helper. -
#failure_message ⇒ String
Returns an explanation of why the matcher failed to match with
should
. -
#initialize ⇒ HasDateSelect
constructor
Initializes a HasDateSelect matcher.
-
#negative_failure_message ⇒ String
Returns an explanation of why the matcher failed to match with
should_not
.
Methods included from RSpec::TagMatchers::Helpers::SentenceHelper
Methods inherited from MultipleInputMatcher
Constructor Details
Instance Method Details
#description ⇒ String
Returns a description of the matcher’s criteria.
76 77 78 |
# File 'lib/rspec/tag_matchers/has_date_select.rb', line 76 def description [basic_description, extra_description].compact.reject(&:empty?).join(" ") end |
#discard(*parts) ⇒ HasDateSelect
This modifier replaces the matchers for the given date components. Any modifiers that were called before this one will be lost for those matchers. Therefor, discard
should be called before other modifiers, such as for
. For example, the following matcher will only test the input names for the month and day components.
it { should have_date_select.for(:start_date).discard(:year) }
In order to test the input names for all three components, the for
modifier must come after the discard
modifier:
it { should have_date_select.discard(:year).for(:start_date) }
Specifies that one or more components of the date will be hidden by Rails’ date_select
helper. For example, calling date_select
with the option :discard_day => true
produces two <select> elments (for the year and month components) and one hidden input for the date component:
<select name="model[date(1i)]">...</select>
<select name="model[date(2i)]">...</select>
<input type="hidden" name="model[date(3i)]" />
Since the default is to match three <select> elements, one must call discard(:day) to tell a HasDateSelect matcher to expect a hidden input for the third component.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rspec/tag_matchers/has_date_select.rb', line 62 def discard(*parts) @discard ||= [] @discard += parts parts.each do |part| # TODO: create a HasHiddenInput matcher replace_matcher(part, HasInput.new.with_attribute(:type => :hidden)) end self end |
#failure_message ⇒ String
Returns an explanation of why the matcher failed to match with should
.
83 84 85 |
# File 'lib/rspec/tag_matchers/has_date_select.rb', line 83 def "expected document to #{description}; got: #{@rendered}" end |
#negative_failure_message ⇒ String
Returns an explanation of why the matcher failed to match with should_not
.
90 91 92 |
# File 'lib/rspec/tag_matchers/has_date_select.rb', line 90 def "expected document to not #{description}; got: #{@rendered}" end |