Spec your Cells with rspec-cells

{{{
Today we released “rspec-cells 0.0.1”:https://rubygems.org/gems/rspec-cells which brings @#render_cell@ to your cell examples.

While we ship Cells with a test case for @Test::Unit@ the RSpec example group for cells has been missing for a long time. Based on “Dmytro Shteflyuk’s rspec-cells for RSpec1”:https://github.com/kpumuk/rspec-cells we now *got support for RSpec2*.

h3. Usage

Put the following code in your Rails app’s @Gemfile@.

group :test do
  gem 'rspec-cells'
end

Just drop your examples into @spec/cells/@. Here’s how a cell spec could look like.

describe PostsCell do
  render_views

  it "should render the posts count" do
    render_cell(:posts, :count).should 
      have_selector("p", :content => "4 posts!")
  end
end

So we basically got a @#render_cell@ for specing which simply returns the rendered markup.

To run your examples we got a rake task.

$ rake spec:cells

h3. Is there more?

Presently, we go *without a distinction between controller-only and view-only specs* as you might know from controller specs.

*Views are always rendered in rspec-cells* as in a real functional test.

This is still subject to discussion – if you feel like you could need an explicit way to test your cell class only, or to render your views without executing the state code, let us know.

However, keep in mind that cells should be independent components *cutting monolithic controllers into small manageable pieces*, and thus might not need to be tested on different layers.

Have fun specing your cells and “tell us what you think”:http://cells.rubyforge.org/community.html.
}}}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s