Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

sj26/rspec-rails-assign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSpec Rails Assign

Motivation

This is ugly:

subject { get :show }
specify { subject and assigns[:blah].should be_present }
specify { subject and assigns[:blah].should == "something" }
specify { subject and assigns[:blah].should =~ /thi/ }
specify { subject and assigns[:blah].should be_a String }

Instead:

subject { get :show }
it { should assign :blah }
it { should assign :blah => "something" }
it { should assign :blah => /thi/ }
it { should assign :blah => is_a(String) }

It's more like a subject modifier, a la its, but inline and allowing nicely described specs:

MyController
  #show
    should assign @blah
    should assign @blah == "something"
    should assign @blah =~ /thi/
    should assign @blah to be a kind of String

And presents nice diffs when it fails:

  1) MyController#show assign @blah to == "something"
     Failure/Error: it { should assign :blah => "something" }
       expected: "something"
            got: "other" (using ==)

License

The MIT License, see [LICENSE][license].

About

A nicer way to asset instance variable assignments in controller examples

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages