Check the new repository at github.com/trailblazer/rspec-cells
This plugin allows you to test your cells easily using RSpec. Basically, it adds an example group especially for cells, with several helpers to perform cells rendering.
If you are not sure what is cells, please visit its home page:
If you’re using Rails 2.1, you can simply use “script/plugin”. It will export all the code from GitHub into “vendor/plugins”:
script/plugin install git://github.com/kpumuk/rspec-cells.git
If you are using Rails prior to 2.1, use the following:
cd vendor/plugins git clone git://github.com/kpumuk/rspec-cells.git rm -rf rspec-cells/.git cd ../..
To continuously track meta-tags development, it’s probably best to install it as a plugin using some vendor branch management tool like Braid:
gem install evilchelu-braid
Using Braid to add a Rails plugin is simple:
# (make sure you've committed everything first) braid add -p git://github.com/kpumuk/rspec-cells.git # now you should have the library in vendor/plugins/rspec-cells
After that is done, add following line into your spec_helper.rb
:
require 'spec/cells'
Put all your cells specs under spec/cells
folder. Here is how spec looks like in general:
describe VideoCell do integrate_views context '.videos' do it 'should initialize :videos variable' do params[:id] = 10 session[:user_id] = 20 opts[:opt] = 'value' result = render_cell :videos, { :videos => [] }, :slug => 'hello' result.should have_tag('div', :class => :videos) end end end
Please note: when you don’t pass a cell to describe, like this:
describe ThingsCell do
then you must provide a cell_name
within the context of your cell specs:
describe "ThingCell" do cell_name :thing
In your spec you can use render_cell
method to perform cell rendering.
By default rendering will not be performed, only code from cell class will be called. To do rendering, add integrate_views!
statement in your describe
block (just like you do for controllers).
From your spec you have access to several variables:
-
opts
— options being passed to cell. -
params
— request parameters. -
session
— current session. -
request
— request object. -
assigns
— an array of cell instance variables.
This plugin has been created in Scribd.com for our internal use and then the sources were opened for other people to use. All the code in this package has been developed by Dmytro Shteflyuk for Scribd.com and is released under the MIT license. For more details, see the MIT-LICENSE file.
-
Dmytro Shteflyuk (author) <[email protected]> kpumuk.info