Repository is archived
No commit activity in last 3 years
No release in over 3 years
A subject-oriented way to match assignments in controller examples.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.7.0

Runtime

 Project Readme

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].