Skip to content

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

Notifications You must be signed in to change notification settings

brentvatne/rspec-lets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 })

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages