Skip to content
This repository has been archived by the owner on Nov 19, 2022. It is now read-only.

kpumuk/rspec-cells

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project had been moved

Check the new repository at github.com/trailblazer/rspec-cells

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:

cells.rubyforge.org/

Installation

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'

Usage

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.

Who are the authors?

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.

Credits

  • Dmytro Shteflyuk (author) <kpumuk@kpumuk.info> kpumuk.info

About

A library for testing applications that are using Cells in RSpec.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published