Skip to content
This repository has been archived by the owner on Feb 21, 2021. It is now read-only.

Commit

Permalink
adding spec for devise_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mstubna committed Feb 15, 2015
1 parent 08fabba commit c8b2d9d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/helpers/devise_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'rails_helper'

RSpec.describe DeviseHelper, type: :helper do
describe '#devise_error_messages!' do
subject { helper.devise_error_messages! }

# create a mock of the Devise Controller resource method
before do
class MockResource
def errors
MockError.new
end
end
def helper.resource
MockResource.new
end
end

context 'When the controller.resource contains no errors' do
class MockError
def empty?
true
end
end
example { expect(subject).to be_nil }
end

context 'When the controller.resource contains an error' do
class MockError
def empty?
false
end

def full_messages
[{ msg: 'an error message' }]
end
end

example { expect(subject).to be_nil }

example do
subject
expect(helper).to set_flash[:devise_error].now
end
end
end
end

0 comments on commit c8b2d9d

Please sign in to comment.