require 'spec_helper' require 'bh/helpers/form_for_helper' include Bh::FormForHelper def self.field_helpers_to_test types = %w(email file number password phone search telephone text url) if defined?(ActionView::VERSION) # only defined in ActionView >=4 # types.concat %w(color date datetime datetime_local month time week) end types.map{|type| "#{type}_field"} << "text_area" end field_helpers_to_test.each do |form_field| describe form_field do attr_accessor :output_buffer let(:protect_against_forgery?) { false } let(:form) { form_for user, layout: layout, errors: errors, url: '/', &block } let(:user) { User.new } let(:errors) { {} } let(:block) { Proc.new {|f| f.send form_field, :name, options} } let(:options) { {} } context 'given any layout' do let(:layout) { :whatever } specify 'not given a placeholder option, automatically generates one' do expect(form).to include 'placeholder="Name"' end context 'given a placeholder option, uses the provided one' do let(:options) { {placeholder: 'Given name'} } it { expect(form).to include 'placeholder="Given name"' } end specify 'not given a label option, automatically generates one' do expect(form).to include 'Name' end context 'given a label option, uses the provided one' do let(:options) { {label: 'Given name'} } it { expect(form).to include 'Given name' } end specify 'not given a prefix or suffix option, does not use an input group' do expect(form).not_to include 'input-group' end context 'given a prefix option, prints the prefix before the field' do let(:options) { {prefix: 'Mr.'} } it { expect(form).to include '