Skip to content
Spec your Cells.
Ruby HTML
Branch: master
Clone or download
Pull request Compare This branch is 198 commits ahead, 1 commit behind kpumuk:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gemfiles load rspec/cells in rspec-cells, so you don't have to do it. May 28, 2015
lib Support rspec-rails 4.x (#88) Nov 6, 2019
spec use let instead of overriding methods. Jun 1, 2015
.gitignore tests for rspec2 and rspec3 Jun 6, 2014
.travis.yml Fix travis (#89) Nov 6, 2019
CHANGES.md Releasing v0.3.5 Nov 6, 2019
Gemfile remove appraisals. May 9, 2016
MIT-LICENSE relaxed rspec-rails version Jun 11, 2014
README.md
Rakefile Added 'rake spec' task. Sep 26, 2011
rspec-cells.gemspec Add project metadata to the gemspec (#90) Nov 8, 2019

README.md

Rspec-Cells

Spec your Cells.

This plugin allows you to spec your cells with RSpec.

Cells is Rails' popular view components framework.

Installation

This gem runs with RSpec3 and Rails >= 3.x and Cells 4. Add it to your app's Gemfile.

group :development, :test do
  gem "rspec-cells"
end

Note: In case you're still using Cells 3, go here.

Usage

Simply put all your specs in the spec/cells directory or add type: :cell to the describe block. However, let the cell generator do that for you!

  rails g rspec:cell comment show

will create an exemplary spec/cells/comment_cell_spec.rb for you.

API

To invoke rendering of a cell you use the exact same API as in your application.

describe CommentCell do
  it "renders comment" do
    expect(cell(:comment).call).to have_content "Really Great!"
  end
end

As you can see, it is nothing more than using #cell or #concept, invoke the default state using #call (or any other state with call(:other_state)) and use Rspecs and Capybara's matchers.

URL helpers

If your cells use helpers with controller dependency, you need to specify a controller to use in your test.

describe CommentCell do
  controller CommentsController

Excuse the clumsiness, but this is done wrong in Rails and not Cells' fault.

Running Specs

Run your examples with

rake spec:cells

More docs

All the docs about testing can be found on the Trailblazer project page.

Test cells with caching

By default your code for caching code is not run if you set ActionController::Base.perform_caching = false That's a reasonable default but you might want to increase coverage by running caching code at least once. Here is an example:

  describe SomeCell do
    describe 'caching' do
      enable_cell_caching!
      # Code for testing...
    end
  end

Contributors

Big thanks to folks who helped me a lot.

  • Jorge Calás Lozano calas@qvitta.net (Cleanup, capybara string matchers)
  • Abdelkader Boudih <@seuros>

LICENSE

Copyright (c) 2010-2015, Nick Sutterer

Copyright (c) 2008-2009, Dmytro Shteflyuk kpumuk@kpumuk.info http://kpumuk.info

Released under the MIT License.

You can’t perform that action at this time.