Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Spec your Cells.
tag: v0.0.5

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
CHANGES.textile
Gemfile
MIT-LICENSE
README.rdoc
Rakefile
rspec-cells.gemspec

README.rdoc

Rspec Cells

Spec your Cells.

This plugin allows you to test your cells easily using RSpec. Basically, it adds a cells example group with a #render_cell helper.

Cells is Rails' popular view components framework.

Installation

This gem runs with RSpec2 and Rails 3.0, so just add it to your app's Gemfile.

group :test do
  gem "rspec-cells"

Usage

Simply put all your specs in the spec/cells directory. However, let the cell generator do that for you!

rails g cell blog_post show -t rspec

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

Webrat

Webrat matchers just work as you might have expected - here is how a simple spec could look like.

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

Capybara

If you want Capybara's string matchers be sure to bundle at least capybara 0.4.1 in your Gemfile.

gem "capybara", "~> 0.4.1"

You can then use capybara's matchers in your cell spec.

describe PostsCell do
  describe "search posts" do
    let(:search) { render_cell(:posts, :search) }

    it "should have a search field" do
      search.should have_field("Search by Title")
    end

    it "should have a search button" do
      search.should have_button("Search")
    end
  end

  describe "latest posts" do
    subject { render_cell(:posts, :latest) }

    it { should have_css("h3.title", :text => "Latest Posts") }
    it { should have_table("latest_posts") }
    it { should have_link("View all Posts") }
    it { should_not have_button("Create Post") }
    it { should_not have_field("Search by Title") }
  end
end

You can see all capybara matchers and finders here: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Simple

Running the specs

Run your examples with

rake spec:cells

If you need more helpers, matchers and stuff, just let us know.

Contributors

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

LICENSE

Copyright © 2010, Nick Sutterer

Copyright © 2007-2009, Dmytro Shteflyuk <kpumuk@kpumuk.info> kpumuk.info

Released under the MIT License.

Something went wrong with that request. Please try again.