<commit_before># Seatbelt

[![Build Status](https://secure.travis-ci.org/alto/seatbelt.png)](http://travis-ci.org/alto/seatbelt)
[![Code Climate](https://codeclimate.com/github/alto/seatbelt.png)](https://codeclimate.com/github/alto/seatbelt)
[![Coverage Status](https://coveralls.io/repos/aasm/aasm/badge.png?branch=master)](https://coveralls.io/r/aasm/aasm)

Seatbelt provides a number of custom, high-level assertions for Ruby and Ruby on Rails. The assertions work well with Ruby
[1.8.7](http://ruby-doc.org/core-1.8.7/),
[1.9.2](http://ruby-doc.org/core-1.9.2/),
[1.9.3](http://ruby-doc.org/core-1.9.3/),
[2.0.0](http://ruby-doc.org/core-2.0.0/) and
[2.1.0](http://ruby-doc.org/core-2.1.0/).
This includes compatibility with
[test/unit](http://ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/index.html) and
[minitest](http://ruby-doc.org/stdlib-1.9.3/libdoc/minitest/unit/rdoc/index.html).

## Installation

Add this line to your application's Gemfile:

    gem 'seatbelt'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install seatbelt

## Usage

### assert_json

Test your [JSON](http://www.json.org/) strings

```ruby
class MyActionTest < ActionController::TestCase
  include Seatbelt::AssertJson

  def test_my_action
    get :my_action, :format => 'json'
    # => @response.body= '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}]}'

    assert_json @response.body do
      has 'key' do
        has 'inner_key1', 'value1'
        has 'inner_key2', /lue2/
      end
      has_not 'key_not_included'
    end
  end

end
```

### assert_mail

Test your Rails [ActionMailer](http://guides.rubyonrails.org/action_mailer_basics.html) deliveries.

```ruby
class MyTest < Test::Unit::TestCase

  def test_mail
    this_sends_an_email
    assert_mail :to => '<EMAIL>', :subject => 'the subject'
  end

  def test_with_block
    assert_mail :to => '<EMAIL>', :subject => 'the subject' do
      assert_mail :to => '<EMAIL>', :subject => 'used as regular expression' do
        this_sends_two_emails
      end
    end
  end

  def test_the_mail_body
    assert_mail :to => '<EMAIL>', :body => ['part 1', 'part 2'] do
      this_sends_an_email
    end
  end

  def test_the_full_mail
    assert_mail :from     => '<EMAIL>',
                :to       => '<EMAIL>',
                :cc       => '<EMAIL>',
                :bcc      => '<EMAIL>',
                :subject  => 'subject',
                :body     => ['part 1', 'part 2'] do
      this_sends_an_email
    end
  end

  def test_crosscheck
    assert_no_mail do
      this_should_not_send_an_email
    end
  end

  def test_other_crosscheck
    assert_no_mail :to => '<EMAIL>' do
      this_should_not_send_an_email
    end
  end

end
```


## Changelog ##

Look at the [CHANGELOG](https://github.com/xing/assert_json/blob/master/CHANGELOG.md) for details.

## Authors ##

  * [<NAME>](http://github.com/alto)<commit_msg>show example in readme<commit_after># Seatbelt

[![Build Status](https://secure.travis-ci.org/alto/seatbelt.png)](http://travis-ci.org/alto/seatbelt)
[![Code Climate](https://codeclimate.com/github/alto/seatbelt.png)](https://codeclimate.com/github/alto/seatbelt)
[![Coverage Status](https://coveralls.io/repos/aasm/aasm/badge.png?branch=master)](https://coveralls.io/r/aasm/aasm)

Seatbelt provides a number of custom, high-level assertions for Ruby and Ruby on Rails. The assertions work well with Ruby
[1.8.7](http://ruby-doc.org/core-1.8.7/),
[1.9.2](http://ruby-doc.org/core-1.9.2/),
[1.9.3](http://ruby-doc.org/core-1.9.3/),
[2.0.0](http://ruby-doc.org/core-2.0.0/) and
[2.1.0](http://ruby-doc.org/core-2.1.0/).
This includes compatibility with
[test/unit](http://ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/index.html) and
[minitest](http://ruby-doc.org/stdlib-1.9.3/libdoc/minitest/unit/rdoc/index.html).

## Installation

Add this line to your application's Gemfile:

    gem 'seatbelt'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install seatbelt

## Usage

### assert_json

Test your [JSON](http://www.json.org/) strings

```ruby
class MyActionTest < ActionController::TestCase
  include Seatbelt::AssertJson

  def test_my_action
    get :my_action, :format => 'json'
    # => @response.body= '{"key":[{"inner_key1":"value1"},{"inner_key2":"value2"}]}'

    assert_json @response.body do
      has 'key' do
        has 'inner_key1', 'value1'
        has 'inner_key2', /lue2/
      end
      has_not 'key_not_included'
    end
  end

end
```

### assert_mail

Test your Rails [ActionMailer](http://guides.rubyonrails.org/action_mailer_basics.html) deliveries.

```ruby
class MyTest < Test::Unit::TestCase

  def test_mail
    this_sends_an_email
    assert_mail :to => '<EMAIL>', :subject => 'the subject'
  end

  def test_with_block
    assert_mail :to => '<EMAIL>', :subject => 'the subject' do
      assert_mail :to => '<EMAIL>', :subject => 'used as regular expression' do
        this_sends_two_emails
      end
    end
  end

  def test_the_mail_body
    assert_mail :to => '<EMAIL>', :body => ['part 1', 'part 2'] do
      this_sends_an_email
    end
  end

  def test_the_full_mail
    assert_mail :from     => '<EMAIL>',
                :to       => '<EMAIL>',
                :cc       => '<EMAIL>',
                :bcc      => '<EMAIL>',
                :subject  => 'subject',
                :body     => ['part 1', 'part 2'] do
      this_sends_an_email
    end
  end

  def test_crosscheck
    refute_mail do
      this_should_not_send_an_email
    end
  end

  def test_other_crosscheck
    assert_no_mail :to => '<EMAIL>' do
      this_should_not_send_an_email
    end
  end

end
```


## Changelog ##

Look at the [CHANGELOG](https://github.com/xing/assert_json/blob/master/CHANGELOG.md) for details.

## Authors ##

  * [<NAME>](http://github.com/alto)
{'fraction_non_alphanumeric': 0.1610024030209406, 'fraction_numerical': 0.016477857878475798, 'mean_word_length': 3.0409153952843275, 'pattern_counts': {'":': 6, '<': 27, '<?xml version=': 0, '>': 57, 'https://': 12, 'lorem ipsum': 0, 'www.': 2, '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': '3560334', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2118, 'n_words': 412}