Rspec On Rails Matchers plugin

Plugin details

Adds the following RSpec matchers:
Associations:
Verify that the association has been defined. (doesn't verify that the association works!)

* Validations:
Verify that a validation has been defined. (doesn't test the validation itself)

* Views:
Verifies that the views contains some tags.

Websitehttp://code.google.com/p/rspec-on-rails-matchers/ Repositoryhttp://rspec-on-rails-matchers.googlecode.com/svn/trunk/ Author Josh Knowles, Bryan Helmkamp, Matt Aimonetti Tags RSpec LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://rspec-on-rails-matchers.googlecode.com/svn/trunk/

In your view spec:

    it "should render new form" do
        render "/users/new.html.erb"

        response.should have_form_posting_to(users_path) do
          with_text_field_for(:user_name)
          with_text_area_for(:user_address)
          with_text_field_for(:user_login)
          with_text_field_for(:user_email)
          with_submit_button
        end
    end



In your model spec:

    describe User do
      before(:each) do
        @user = User.new
      end

      it "should have many posts" do
        @user.should have_many(:posts)
      end

      it "should belong to a group" do
        @user.should belong_to(:group)
      end
      
      it do
        @user.should validate_presence_of(:email)
      end

      it do
        @user.should validate_uniqueness_of(:email)
      end

      it do
        @user.should validate_uniqueness_of(:login)
      end

      it do
        @user.should validate_presence_of(:login)
      end

      it do
        @user.should validate_presence_of(:name)
      end
      
      it do
        @user.should validate_length_of(:password, :between => 4..40)
      end  

      it do
        @user.should validate_confirmation_of(:password)
      end

    end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: Guest, 10 months ago