Sha256: cac7fb82fcde11d95e02719ca3efbb9a92213aa8420576153ec0828f8e501d5b
Contents?: true
Size: 1.61 KB
Versions: 3
Compression:
Stored size: 1.61 KB
Contents
# frozen_string_literal: true require 'rails_helper' require 'formify/spec_helpers' describe Forms::<%= class_name %>, type: :form do include Formify::SpecHelpers <% all_attributes.each do |attr| -%> <% if factory_bot? && factory?(attr) -%> let(:<%= attr %>) { FacotryBot.create(<%= attr %>) } <% else -%> let(:<%= attr %>) { <%= attr.upcase %>_VALUE } <% end -%> <% end -%> <% if spec_comments? -%> # :attributes is used to initialize the form. # These values should result in a valid form. # You can override these in blocks or use let(:attributes_override) { { foo: bar } } <% end -%> let(:attributes) do { <% all_attributes.each_with_index do |attr, i| -%> <%= attr %>: <%= attr %><%= ',' unless all_attributes.count == (i + 1)%> <% end -%> } end it { expect_valid }<% if spec_comments? -%> # Expect the form to be valid<% end -%> it { expect(result).to be_success } it { expect(value).to be_a(<%= inferred_model_name %>) }<% if spec_comments? -%> # Model name inferred<% end -%> <% all_attributes.each do |attr| -%> describe '#<%= attr %>' do it { expect_error_with_missing_attribute(:<%= attr %>) } xit { expect_error_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_BAD_VALUE, message: nil) } # :message is optional xit { expect_valid_with_attribute_value(:<%= attr %>, <%= attr.upcase %>_GOOD_VALUE) } end <% end -%> <% if spec_comments? -%> # Other Expectation Helpers # xit { expect_error_message(message) } # xit { expect_error_with_attribute(attribute) } # xit { expect_not_valid(attribute: nil, message: nil) } # :attribute and :message are optional <% end -%> end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
formify-0.18.2 | lib/generators/form/templates/form_spec.rb.tt |
formify-0.18.1 | lib/generators/form/templates/form_spec.rb.tt |
formify-0.18.0 | lib/generators/form/templates/form_spec.rb.tt |