Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

insist

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insist

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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!

FAQs

Package last updated on 06 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc