User:Mahhegde/sandbox

Rspec::Expectations
Rspec is a Behavior Driven Development (BDD ) testing framework. Rspec::Expectations lets the programmer to specify the expected outcome of an object in unit testing.

Usage Example
Rspec::Expectation has many methods which helps in verifying the returned result. expect statement takes the argument to be tested and makes the validation based on the qualifiers provided as an argument. The  method is used with   statement. As the name indicates,  method tests the actual argument against expected argument based on matcher's provided as an argument. In the above example, expect statement uses special Rspec keyword  matcher. This matcher takes the expected value and passes unit test if actual value is same as expected value. Example test case passes only if the returned value from the actual method call  is 'Good Morning!', otherwise test fails. In case of failure Rspec throws an error and indicates expected and observed values do not match. The programmer can also use  Rspec method for exact opposite matching.

method was introducued in Rspec version 2.11. Before that  and   syntax were used. Latest rspec versions supports both  and   syntax. But  is recommended over. There are several built in matchers in Rspec which can be used with expect..to or expect..not_to to define the expectations on an object. Let's refer  as Expectation.

MiniTest::Expectations
MiniTest is a testing framework which provides a complete set of testing utilities including mocking, benchmarking and Behaviour Driven Development. From Ruby 1.9,

it's added as part of Ruby's standard library. MiniTest provides expectation syntax which is similar to Rspec Expectation syntax.

Usage Example
Example shown above is almost similar to the example given in Rspec::Expectations section. Instead of  syntax, MiniTest uses

But both the frameworks tests the value of actual and expected objects for equality. MiniTest::Expectations provides several inbuilt methods.

Built in methods
Above built in methods are positive expectations. MiniTest also provides built in negative expectation methods. In most of the cases we just need to replace   For example,   etc.