= Fluidity

== Should

require ‘fluidity/should’

Now we have a fluent notation with which to make assertions.

true.should.be.true false.should.be.false

(5 + 5).should.equal 10

[1,2,3].should.include(2)

We can also use the associated operator (Ruby’s built-in query method name).

false.should.be.false? true.should.be.true?

(5 + 5).should == 10

Indefinite article a and an are suppored.

12.should.be.a.kind_of?(Integer)

As is not for negation.

12.should.not.equal(20)

We should also make sure such assertions can fail.

IncludeAssay.should.be.raised do [1,2,3].should.include(4) end

FalseAssay.should.be.raised do true.should.be.false end

EqualAssay.should.be.raised do (5 + 5).should == 11 end

Matcher notation is also supported, if you have any matcher classes to use. Assay classes can be converted to matchers, so we can use one of those to try this out.

be_sixteen = EqualAssay

16.should be_sixteen

15.should_not be_sixteen

== Must

require ‘fluidity/must’

Now we have a fluent notation with which to make assertions.

true.must.be.true false.must.be.false

(5 + 5).must.equal 10

[1,2,3].must.include(2)

We can also use the associated operator (Ruby’s built-in query method name).

false.must.be.false? true.must.be.true?

(5 + 5).must == 10

Indefinite article a and an are suppored.

12.must.be.a.kind_of?(Integer)

12.must.be.an.instance_of?(Fixnum)

As is not for negation.

12.must.not.equal(20)

Or must_not can also be used.

12.must_not.equal(20)

We must also make sure such assertions can fail.

IncludeAssay.must.be.raised do [1,2,3].must.include(4) end

FalseAssay.must.be.raised do true.must.be.false end

EqualAssay.must.be.raised do (5 + 5).must == 11 end

Matcher notation is also supported, if you have any matcher classes to use. Assay classes can be converted to matchers, so we can use one of those to try this out.

be_sixteen = EqualAssay

16.must be_sixteen

15.must_not be_sixteen

= Grammer

require ‘fluidity/assert’

Now we have a fluent notation with which to make assertions.

true.assert.true false.assert.false

(5 + 5).must.equal 10

[1,2,3].must.include(2)

We can also use the associated operator (Ruby’s built-in query method name).

false.assert.false? true.assert.true?

(5 + 5).assert == 10

(9 + 9).assert.not == 10

12.assert.kind_of?(Integer)

As is not for negation.

12.assert.not.equal(20)

Or should_not can also be used.

12.should_not.equal(20)

We must also make sure such assertions can fail. Since assert is special method to assay classes, we can use it as on these as part of our test grmmer. So we use the raw #assert! method to handle the test.

RaiseAssay.assert!(IncludeAssay) do [1,2,3].assert.include(4) end

RaiseAssay.assert!(FalseAssay) do true.assert.false end

RaiseAssay.assert!(EqualityAssay) do (5 + 5).assert == 11 end

Matcher notation is also supported, if you have any matcher classes to use. Assay classes can be converted to matchers, so we can use one of those to try this out.

is_sixteen = EqualityAssay

16.assert is_sixteen

== Other Stuff

What if there is an assertion made for which no Assay class exists? If the target object has a query method defined by the same name, that is, one ending in a ? mark, then that mehtod will be used to test the assertion.

c = Class.new do def initialize(truth) @truth = truth end def yes? @truth end def no? !@truth end end

x = c.new(true)

x.should.be.yes

x.should_not.be.no