require 'rails_helper' require 'bh/core_ext/rails/form_for_helper' include Bh::Rails::Helpers describe 'select' do 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.select :name, [['Jeremy', 1]], options} } let(:options) { {} } context 'given any layout' do let(:layout) { :whatever } 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 context 'not given a help option, does not display a help box' do it { expect(form).not_to include 'help-block' } end context 'given a help option, displays a help box' do let(:options) { {help: 'Please select an option'} } it { expect(form).to include 'Please select an option' } end specify 'not given an error, does not apply has-error to the form group' do expect(form).not_to include 'has-error' end context 'given an error' do before { user.errors.add :name, 'cannot be nil' } specify 'shows errors and error messages' do expect(form).to include 'has-error' expect(form).to include 'cannot be nil' end specify 'does not show error icons' do expect(form).not_to include 'has-feedback' end end end describe 'given a basic layout' do let(:layout) { :basic } specify 'applies form-group to the container, form-control to the input' do expect(form).to match %r{