Project

rspec-lets

0.0
No commit activity in last 3 years
No release in over 3 years
lets and lets! to declare multiple variables in one call.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

rspec-lets

lets and lets! as an alternate syntax for let and let! that allow you to define multiple variables within one call, for cleaner definitions of test variables. As a bonus, you also get help to define helper methods in the same declarative way!

Usage

Add this to your Gemfile:

gem 'rspec-lets', group: :test

In your spec_helper add:

# At the top of the file
require 'rspec-lets/helper'

# In the config block
config.extend RSpecLets::Helper

In your specs, instead of writing:

let(:admin) { create(:admin) }
let(:user)  { create(:user)  }

You can now write:

lets(admin: -> { create(:admin) },
     user:  -> { create(:user) })

Or alternatively:

lets([:admin, :user] =>
     ->(i, key) { create(key) })

The same syntax applies for lets!.

You can also define a helper method in the same style:

help(foo: ->(val) { val * 2 })