<commit_before>h1. Neato Assertions

h2. This project needs a new name.

Neato Assertions provides flexible xUnit style matchers dynamically.
This library works well with something like "Context":http://github.com/jeremymcanally/context.

h2. Dynamic assertions

h3. Background & Philosophy

Rspec has never sat well for me.  Object.method.should be_true style testing reads neat and is
really nicely like english.  Here's the problem: What we are strictly saying in rspec is that
testing is the object's responsibility.  It's like "hey, you! test yourself."

Testing is definitionally an external act.  It is manipulating a system by its control points
(public api) and confirming that the behavior is as expected.  Passing a "modal verb":http://en.wikipedia.org/wiki/Modal_verb
like "should" to the object in question does not describe this behavior.

From a more practical perspective, defining rspec behaviors is way too much of a pain when we already have
an easy way to define methods in ruby.

@Test::Unit@, particularly when combined with Context or Shoulda, is good enough for most things.
The only real issue is that you find yourself defining a whole lot of helper methods, like @assert_new_record@, @assert_valid@, @assert_red@
*Dynamic assertions* fixes this.  With the fantastic power of method missing, assertions are generated on the fly.
One of the really nice things about Rspec is that every matcher automatically gets an inverse (logical not) matcher.
*Dynamic assertions* provides this as well.

h3. Example

Let's say we have class named @Entry@ that has a boolean @published?@ and a
boolean @saved?@ and a record @@foo@ that should be saved but not published.
Oh, and it should have a user, which we'll represent as the string @"joe"@

h4. Positive assertions

In Rspec: @@foo.should be_saved@

In Test::Unit: @assert @foo.saved?@

With Dynamic assertions: @assert_saved @foo@

h4. Negative assertions

In Rspec: @@foo.should_not be_published@

In Test::Unit: <code>assert !@foo.published?</code> or, if you've defined @assert_false@, <code>assert_false @foo.published</code>

With Dynamic assertions: <code>assert_not_published @foo</code>

h4. Positive equality assertions

In Rspec: <code>@foo.user.should == "joe"</code>

In Test::Unit: <code>assert_equal "joe", @foo.user</code>

With Dynamic assertions: <code>assert_user "joe", @foo</code>

h4. Negative equality assertions

In Rspec: <code>@foo.user.should == "joe"</code>

In Test::Unit: <code>assert_not_equal "joe", @foo.user</code>

With Dynamic assertions: <code>assert_not_user "joe", @foo</code>

h2. Smarter Message

My bane: "false did not equal true" -- What you really want to know is what the variable names were or the method calls.
If we have the stack trace, we should be able to show you the exact test that failed immediately.  Smarter Message does exactly that.

<pre><code>
#demo_test.rb
require File.join(File.dirname(__FILE__), "test_helper")
require 'smarter_message'

class DemoTest < Test::Unit::TestCase
  include NeatoAssertions::SmarterMessage
  test "demonstration" do<commit_msg>formatting<commit_after>h1. Neato Assertions

h2. This project needs a new name.

Neato Assertions provides two separate modules that work together.
*Dynamic assertions* are flexible xUnit style matchers called dynamically.
*Smarter message* supplements test failure messages with a several-line context
of the test failure.
This library works well with something like "Context":http://github.com/jeremymcanally/context.

h2. Dynamic assertions

h3. Background & Philosophy

Rspec has never sat well for me.  Object.method.should be_true style testing reads neat and is
really nicely like english.  Here's the problem: What we are strictly saying in rspec is that
testing is the object's responsibility.  It's like "hey, you! test yourself."

Testing is definitionally an external act.  It is manipulating a system by its control points
(public api) and confirming that the behavior is as expected.  Passing a "modal verb":http://en.wikipedia.org/wiki/Modal_verb
like "should" to the object in question does not describe this behavior.

From a more practical perspective, defining rspec behaviors is way too much of a pain when we already have
an easy way to define methods in ruby.

@Test::Unit@, particularly when combined with Context or Shoulda, is good
enough for most things.  The only real issue is that you find yourself defining
a whole lot of helper methods, like @assert_new_record@, @assert_valid@, @assert_red@
*Dynamic assertions* fixes this.  With the fantastic power of method missing,
assertions are generated on the fly.

One of the really nice things about Rspec is that every matcher automatically
gets an inverse (logical not) matcher. *Dynamic assertions* provides this as well.

h3. Example

Let's say we have class named @Entry@ that has a boolean @published?@ and a
boolean @saved?@ and a record @@foo@ that should be saved but not published.
Oh, and it should have a user, which we'll represent as the string @"joe"@

h4. Positive assertions

In Rspec: @@foo.should be_saved@

In Test::Unit: @assert @foo.saved?@

With Dynamic assertions: @assert_saved @foo@

h4. Negative assertions

In Rspec: @@foo.should_not be_published@

In Test::Unit: <code>assert !@foo.published?</code> or, if you've defined @assert_false@, <code>assert_false @foo.published</code>

With Dynamic assertions: <code>assert_not_published @foo</code>

h4. Positive equality assertions

In Rspec: <code>@foo.user.should == "joe"</code>

In Test::Unit: <code>assert_equal "joe", @foo.user</code>

With Dynamic assertions: <code>assert_user "joe", @foo</code>

h4. Negative equality assertions

In Rspec: <code>@foo.user.should == "joe"</code>

In Test::Unit: <code>assert_not_equal "joe", @foo.user</code>

With Dynamic assertions: <code>assert_not_user "joe", @foo</code>

h2. Smarter Message

My bane: "false did not equal true" -- What you really want to know is what
the variable names were or the method calls.

If we have the stack trace, we should be able to show you the exact test that
failed immediately.  Smarter Message does exactly that.

<pre><code>
#demo_test.rb
require File.join(File.dirname(__FILE__), "test_helper")
require 'smarter_message'

class DemoTest < Test::Unit::TestCase
  include NeatoAssertions::SmarterMessage
  test "demonstration" do
{'fraction_non_alphanumeric': 0.0848551637279597, 'fraction_numerical': 0.0031486146095717885, 'mean_word_length': 4.9764816556914395, 'pattern_counts': {'":': 4, '<': 45, '<?xml version=': 0, '>': 43, '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': '566337', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1804, 'n_words': 829}