|
| 1 | += bluff |
| 2 | + |
| 3 | +* https://github.com/islandr/bluff |
| 4 | + |
| 5 | +== DESCRIPTION: |
| 6 | + |
| 7 | +A single source of lies for all your testing needs. |
| 8 | + |
| 9 | +== FEATURES/PROBLEMS: |
| 10 | + |
| 11 | +* TODO |
| 12 | + |
| 13 | +== CONTRIBUTING: |
| 14 | + |
| 15 | +Pull requests are welcome! See the DEVELOPERS section at the bottom of this page for more information. |
| 16 | + |
| 17 | +== SYNOPSIS: |
| 18 | + |
| 19 | +My original intentions for bluff are focused on rails/activerecord but I'm open |
| 20 | +to other libraries if it doesn't pollute the API. |
| 21 | + |
| 22 | +The goal is to minimize the amount of mocking/faking pollution in your test suits, |
| 23 | +and to do so via an API that feels natural to rails/activerecord users. I favor |
| 24 | +a slightly more wordy API for defining bluffs that offers the full power and flexibility |
| 25 | +of Ruby over a cute DSL that limits customization. |
| 26 | + |
| 27 | +=== MODEL AND DATA BLUFFS |
| 28 | + |
| 29 | +Bluff comes with a small set of predefined data bluffs (see lib/bluff/bluffs/data_bluffs.rb) |
| 30 | +but its easy to add your own. |
| 31 | + |
| 32 | +The standard practice is to define your bluffs within spec/bluffs. If you are |
| 33 | +bluffing a model, name the file *_model_\_bluff.rb*. If you need to bluff custom |
| 34 | +data, do so in *data_bluffs.rb*. |
| 35 | + |
| 36 | +A bluff is a bluff, whether it's just a piece of data or a full blown model. All bluffs |
| 37 | +share the same namespace (the root namespace is the *only* namespace) so choose your bluff |
| 38 | +names accordingly. |
| 39 | + |
| 40 | +``` |
| 41 | +# spec/bluffs/user_bluff.rb |
| 42 | +Bluff.for(:user) do |attributes| |
| 43 | + attributes[:name] ||= Bluff.name |
| 44 | + attributes[:email] ||= Bluff.email(attributes[:name]) |
| 45 | + |
| 46 | + # return your bluffed instance |
| 47 | + User.new(attributes) |
| 48 | +end |
| 49 | +
|
| 50 | +# spec/bluffs/data_bluffs.rb |
| 51 | +Bluff.for(:name) { Faker::Name.name } # Call via Bluff.name |
| 52 | +Bluff.for(:company_name) { Faker::Company.name } |
| 53 | +``` |
| 54 | + |
| 55 | +==== CALLING YOUR BLUFFS |
| 56 | +``` |
| 57 | +User.bluff # returns an unsaved instance -- could also use Bluff.user |
| 58 | +User.bluff! # returns a saved instance -- could also use Bluff.user! |
| 59 | +User.bluff({:name => 'Ryan'}) # supply overrides in the attributes hash |
| 60 | +``` |
| 61 | + |
| 62 | +=== METHOD BLUFFS (MOCKS / STUBS) |
| 63 | + |
| 64 | +All objects and classes are given a `bluff()` method, which is |
| 65 | +used for bluffing both models and methods. If given a symbol, the |
| 66 | +`bluff()` method can be used to define method stubs as follows: |
| 67 | + |
| 68 | +``` |
| 69 | +User.bluff(:find) { |id| :value } |
| 70 | +User.bluff(:save) { true } |
| 71 | +
|
| 72 | +user = Bluff.mock |
| 73 | +user.bluff(:name).as(:value) |
| 74 | +``` |
| 75 | + |
| 76 | +The mocking abilities of bluff are no more than a thin wrapper around |
| 77 | +rspec-mocks. Calling `Bluff.mock('account')` is identical to calling `double('account')` |
| 78 | + |
| 79 | +== REQUIREMENTS: |
| 80 | + |
| 81 | +* rspec-mocks |
| 82 | +* faker |
| 83 | + |
| 84 | +== INSTALL: |
| 85 | + |
| 86 | +* `gem install bluff` |
| 87 | +* or simply add bluff to your Gemfile and run `bundle install` |
| 88 | + |
| 89 | +``` |
| 90 | +group :test do |
| 91 | + gem 'bluff' |
| 92 | +end |
| 93 | +``` |
| 94 | + |
| 95 | +== FURTHER READING: |
| 96 | + |
| 97 | +http://faker.rubyforge.org/ |
| 98 | + |
| 99 | +https://www.relishapp.com/rspec/rspec-mocks/ |
| 100 | +https://www.relishapp.com/rspec/rspec-mocks/docs/method-stubs/stub-on-any-instance-of-a-class |
| 101 | +https://www.relishapp.com/rspec/rspec-mocks/docs/outside-rspec/configure-any-test-framework-to-use-rspec-mocks |
| 102 | + |
| 103 | +== DEVELOPERS: |
| 104 | + |
| 105 | +After checking out the source, run: |
| 106 | + |
| 107 | + $ rake setup |
| 108 | + |
| 109 | +This task will install any missing dependencies and run the tests/specs. |
| 110 | + |
| 111 | +== LICENSE: |
| 112 | + |
| 113 | +(The MIT License) |
| 114 | + |
| 115 | +Copyright (c) 2011 Ryan Mohr (github.com/islandr) |
| 116 | + |
| 117 | +Permission is hereby granted, free of charge, to any person obtaining |
| 118 | +a copy of this software and associated documentation files (the |
| 119 | +'Software'), to deal in the Software without restriction, including |
| 120 | +without limitation the rights to use, copy, modify, merge, publish, |
| 121 | +distribute, sublicense, and/or sell copies of the Software, and to |
| 122 | +permit persons to whom the Software is furnished to do so, subject to |
| 123 | +the following conditions: |
| 124 | + |
| 125 | +The above copyright notice and this permission notice shall be |
| 126 | +included in all copies or substantial portions of the Software. |
| 127 | + |
| 128 | +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
| 129 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 130 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 131 | +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 132 | +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 133 | +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 134 | +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
0 commit comments