Project

lowfive

0.0
No commit activity in last 3 years
No release in over 3 years
Rspec Devise login and logout helpers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.14
~> 2.14
~> 0.10.4
~> 10.0
~> 0.49.1
~> 1.3.13

Runtime

~> 4.3.0
~> 5.1.2
~> 3.6.0
 Project Readme

Low Five

Low Five allows you to easily login a resource using devise in your rspec specs.

You can use these methods inside your specs for:

  • controllers
  • requests
  • features

Make sure that your specs have the correct type: defined.

RSpec.describe UserManagement, type: :request do
end

Installation

Add this line to your application's Gemfile:

gem 'lowfive'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lowfive

Setup

Add this require to your rails_helper.rb file.

require 'lowfive/devise/rspec'

Usage

Low Five provides helper methods that allow you to sign in a particular resource.

First you must create a resource, in our example we use FactoryGirl to create a user instance.

# spec/factories/users.rb

FactoryGirl.define do
  factory :user do
    email 'user@testuser.com'
    name 'Bob Marley'
    password 'Whatever999'
    password_confirmation 'Whatever999'
  end
end

then you pass the user to the helper methods provided. There are two methods available

log_in(resource)
log_out(resource)

Note that you NEED to have a before block to put the helper method into, if you use it outside of an it block.

require 'rails_helper'

RSpec.describe UserManagement, type: :request do
  let(:user) { FactoryGirl.create(:user) }

  before do
    log_in(user)
  end

  describe '#index' do
    context 'logged in' do
      it 'renders index home page' do
        get root_path
        expect(response.body).to include('Home Page')
      end
    end

    context 'logged out' do
      it 'redirects to login page' do
        log_out(user)
        get root_path
        follow_redirect!
        expect(response.body).to include('Log in')
      end
    end
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jwipeout/lowfive. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.