A nicer way to asset instance variable assignments in controller examples
Ruby
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
Gemfile
Gemfile.lock
LICENSE
README.md
rspec-rails-assign.gemspec

README.md

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