-
Notifications
You must be signed in to change notification settings - Fork 13
/
_form.html.erb_spec.rb
36 lines (30 loc) · 1.07 KB
/
_form.html.erb_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'spec_helper'
describe 'records/_form' do
let(:audio) { Audio.new }
let(:form) { AudioForm.new(audio) }
before do
allow(view).to receive(:key).and_return(:title)
allow(view).to receive(:form).and_return(form)
allow(view).to receive(:main_app).and_return(Rails.application.routes.url_helpers)
end
context 'when there are no errors' do
it 'does not have the error class' do
render
expect(response).to have_selector '.form-group'
expect(response).to_not have_selector '.has-error'
end
end
context 'when errors are present' do
let(:errors) { instance_double(ActiveModel::Errors) }
before do
allow(errors).to receive(:[]).and_return(["can't be blank"])
allow(errors).to receive(:full_messages_for).and_return(["can't be blank"])
allow(form).to receive(:errors).and_return(errors)
end
it 'has the error class' do
render
expect(response).to have_selector '.form-group.form-group-invalid'
expect(response).to have_selector '.invalid-feedback', text: "can't be blank"
end
end
end