|
# Stub examples
|
|
# Stub examples
|
|
|
|
|
|
Bellow you will find an example of stub created using Minitest's stub framework. In this example we are using a stub to simulate the behaviour of the *sku_list* method. The original implementation of this method connects to a remote database and returns a huge list (1000+ items) of skus available in the store. For the purpose of this particular test case we do not intend to test the connection with the remote database. We also do not need a huge list of skus, only a few will do. By stubbing this method, we will avoid issues with the remote database and the test will run much faster.
|
|
Bellow you will find an example of stub created using Minitest's stub framework. In this example we are using a stub to simulate the behaviour of the **sku_list** method. The original implementation of this method connects to a remote database and returns a huge list (1000+ items) of skus available in the store. For the purpose of this particular test case we do not intend to test the connection with the remote database. We also do not need a huge list of skus, only a few will do. By stubbing this method, we will avoid issues with the remote database and the test will run much faster.
|
|
|
|
|
|
|
|
|
|
```ruby
|
|
```ruby
|
... | @@ -16,7 +16,7 @@ test "should list skus not generated" do |
... | @@ -16,7 +16,7 @@ test "should list skus not generated" do |
|
end
|
|
end
|
|
```
|
|
```
|
|
|
|
|
|
Another example of stub this time using the [mocha](https://github.com/freerange/mocha) gem. In this example we used a stub to fake the return value of any instance of the method *send_to_gogrids*. This method invokes a service that is used to send an order to an external system. The service returns a link to a file. Since our focus is not to test the integration between the two systems, we stub the method and make it return some predefined url.
|
|
Another example of stub this time using the [mocha](https://github.com/freerange/mocha) gem. In this example we used a stub to fake the return value of any instance of the method **send_to_gogrids**. This method invokes a service that is used to send an order to an external system. The service returns a link to a file. Since our focus is not to test the integration between the two systems, we stub the method and make it return some predefined url.
|
|
|
|
|
|
```ruby
|
|
```ruby
|
|
test "should allow director to send order to production" do
|
|
test "should allow director to send order to production" do
|
... | | ... | |