<commit_before>= Remarkable - Making tests easy on the fingers and eyes for Rspec

Remarkable makes it easy to write elegant, understandable, and maintainable tests.  Remarkable consists of test macros, assertions, and helpers added on to the Test::Unit framework.  It's fully compatible with your existing tests, and requires no retooling to use.

Helpers:: #context and #should give you rSpec like test blocks.
          In addition, you get nested contexts and a much more readable syntax.
Macros:: Generate hundreds of lines of Controller and ActiveRecord tests with these powerful macros.
         They get you started quickly, and can help you ensure that your application is conforming to best practices.
Assertions:: Many common rails testing idioms have been distilled into a set of useful assertions.

= Usage

=== Context Helpers (ThoughtBot::Shoulda::Context)

Stop killing your fingers with all of those underscores...  Name your tests with plain sentences!

  class UserTest << Test::Unit::TestCase
    context "A User instance" do
      setup do
        @user = User.find(:first)
      end

      should "return its full name" do
        assert_equal '<NAME>', @user.full_name
      end

      context "with a profile" do
        setup do
          @user.profile = Profile.find(:first)
        end

        should "return true when sent #has_profile?" do
          assert @user.has_profile?
        end
      end
    end
  end

Produces the following test methods:

  "test: A User instance should return its full name."
  "test: A User instance with a profile should return true when sent #has_profile?."

So readable!

=== ActiveRecord Tests (ThoughtBot::Shoulda::ActiveRecord::Macros)

Quick macro tests for your ActiveRecord associations and validations:

  class PostTest < Test::Unit::TestCase
    fixtures :all

    should_belong_to :user
    should_have_many :tags, :through => :taggings

    should_require_unique_attributes :title
    should_require_attributes :body, :message => /wtf/
    should_require_attributes :title
    should_only_allow_numeric_values_for :user_id
  end

  class UserTest < Test::Unit::TestCase
    should_have_many :posts

    should_not_allow_values_for :email, "blah", "b lah"
    should_allow_values_for :email, "<EMAIL>", "<EMAIL>"
    should_ensure_length_in_range :email, 1..100
    should_ensure_value_in_range :age, 1..100
    should_protect_attributes :password
  end

Makes TDD so much easier.

=== Controller Tests (ThoughtBot::Shoulda::Controller::Macros)

Macros to test the most common controller patterns...

  context "on GET to :show for first record" do
    setup do
      get :show, :id => 1
    end

    should_assign_to :user
    should_respond_with :success
    should_render_template :show
    should_not_set_the_flash

    should "do something else really cool" do
      assert_equal 1, assigns(:user).id
    end
  end

=== Helpful Assertions (ThoughtBot::Shoulda::Assertions)

More to come here, but have fun with what's there.

  assert_same_elements([:a, :b, :c], [:c, :a, :b])
  assert_contains(['a', '1'], /\d/)
  assert_contains(['a', '1'], 'a')

=== 3rd Party and Application Specific Macros

Any *.rb file under RAILS_ROOT/test/shoulda_macros/ or vendor/(plugins|gems)/gem_name/shoulda_macros/ will be automatically required when you run your tests.  This allows you to distribute macros with your plugins, or to organize the macros inside your application.  Remember to add your macro to Test::Unit::TestCase in the macro file:

  # test/shoulda_macros/security.rb
  class Test::Unit::TestCase
    def self.should_be_denied(opts = {})
      should_set_the_flash_to(opts[:flash] || /Please log in/i)
      should_redirect_to(opts[:redirect]   || 'login_url')
    end
  end

= Credits

Remarkable is maintained by [<NAME>](mailto:<EMAIL>)

= License

Remarkable is Copyright © 2008 <NAME>, released under the MIT license<commit_msg>Fix README.<commit_after>= Remarkable - Making tests easy on the fingers and eyes for RSpec

Remarkable makes it easy to write elegant, understandable, and maintainable tests.  Remarkable consists of test macros, assertions, and helpers added on to the RSpec framework.  It's fully compatible with your existing tests, and requires no retooling to use.

= Usage

=== ActiveRecord Tests

Quick macro tests for your ActiveRecord associations and validations:

  describe Post do
    fixtures :all

    should_belong_to :user
    should_have_many :tags, :through => :taggings

    should_require_unique_attributes :title
    should_require_attributes :body, :message => /wtf/
    should_require_attributes :title
    should_only_allow_numeric_values_for :user_id
  end

  describe User do
    should_have_many :posts

    should_not_allow_values_for :email, "blah", "b lah"
    should_allow_values_for :email, "<EMAIL>", "<EMAIL>"
    should_ensure_length_in_range :email, 1..100
    should_ensure_value_in_range :age, 1..100
    should_protect_attributes :password
  end

Makes TDD so much easier.

=== Controller Tests

Macros to test the most common controller patterns...

  describe "on GET to :show for first record" do
    before(:each) do
      get :show, :id => 1
    end

    should_assign_to :user
    should_respond_with :success
    should_render_template :show
    should_not_set_the_flash

    it "do something else really cool" do
      assigns(:user).id.should == 1
    end
  end

= Credits

Remarkable is maintained by [<NAME>](mailto:<EMAIL>)

= License

Remarkable is Copyright © 2008 <NAME>, released under the MIT license
{'fraction_non_alphanumeric': 0.07778177889809147, 'fraction_numerical': 0.005581562837594527, 'mean_word_length': 3.8304347826086955, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1485148', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1577, 'n_words': 601}