Spec your Cells.
This plugin allows you to spec your cells with RSpec.
Cells is Rails' popular [view components framework(http://github.com/apotonick/cells).
This gem runs with RSpec3 and Rails >= 3.x and Cells 4. Add it to your app's
group :development, :test do gem "rspec-cells" end
Note: In case you're still using Cells 3, go here.
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 blog_post show
will create an exemplary spec/cells/blog_post_cell_spec.rb for you.
To invoke rendering of a cell you use the exact same API as in your application.
it "renders post" do expect(cell(:posts).call).to have_content "Really Great!" end
As you can see, it is nothing more than using
#concept, invoke the default state using
#call (or any other state with
call(:other_state)) and use Rspecs and Capybara's matchers.
Run your examples with
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
Big thanks to folks who helped me a lot.
- Jorge Calás Lozano [email protected] (Cleanup, capybara string matchers)
- Abdelkader Boudih <@seuros>
Copyright (c) 2010-2015, Nick Sutterer
Released under the MIT License.