Sha256: afa4d0d4e6f2ae478d7b074e0d1fde1a25f082a71b0a81b40e38dedbe352c69e

Contents?: true

Size: 1.55 KB

Versions: 70

Compression:

Stored size: 1.55 KB

Contents

# insist { on readable assertions }

I like rspec, but I don't like the '#should' junk. It scratches me the wrong
way, I guess. I find this to be an unreadable mess:

    # yuck, if you ask me.
    somevalue.should eq(0)

On the flip side, I really like the idea (make tests read like english).

So instead of slapping '#should' on all objects and doing weird stuff like
`expect { block }.to raise_error(thing)`, I just use blocks for everything in a
kind of lazy-evaluation wrapping:

    # Check equality
    insist { value } == 30

    # Insist an exception is raised
    insist { code }.raises(exception_class)

Reads well, I think.

## Most minimal assertions possible

Using rspec's 'subject' stuff, you can write tests that are perhaps even more minimal while still being clear.

Here's an example test that fails. The subject is an 'insist' object, so you
can just do the usual '==' and other methods on it:

    # spec/example_spec.rb
    describe "thing" do
      subject { insist { "whoa!" } }

      it "should be, like, awesome!" do
        subject == "awesome!"
      end
    end

Running it:

    Failures:

      1) thing should be, like, awesome!
         Failure/Error: subject == "awesome!"
         Insist::Failure:
           Expected "awesome!", but got "whoa!"
         # ./lib/insist/assert.rb:8:in `assert'
         # ./lib/insist/comparators.rb:12:in `=='
         # ./test.rb:5:in `block (2 levels) in <top (required)>'

    Finished in 0.00208 seconds
    1 example, 1 failure

    Failed examples:

    rspec ./test.rb:4 # thing should be, like, awesome!

Version data entries

70 entries across 66 versions & 18 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/insist-1.0.0/README.md