# MockingBird This is a singleton class that helps auto load json_api_client_mocks. Pain point: Setting up client mocks for json_api_client tests can be messy with situations like: ```ruby MyApi::Client::User.set_test_results([some data...], {) MyApi::Client::User.set_test_results([some data...], {) MyApi::Client::User.set_test_results([some data...], {) MyOtherApi::Client::Customer.set_test_results([some data...], {) MyOtherApi::Client::Customer.set_test_results([some data...], {) MyOtherApi::Client::Customer.set_test_results([some data...], {) ``` Placing this anywhere is ugly and time consuming. MockingBird attempts to combine this into a more fixture-like convention by using the file structure of your mocks to build client based test results that are accessible, or just trying to mimic fixtures. ## Installation Add this line to your application's Gemfile: gem 'mocking_bird' And then execute: $ bundle Or install it yourself as: $ gem install mocking_bird ## Usage #### File System Structure In your mock directory you would create the following structure: ``` | |-mocks |-my_api |-customer create.yml delete.yml read.yml update.yml |-user create.yml delete.yml read.yml update.yml |-my_other_api |-order create.yml delete.yml read.yml update.yml |-invocie create.yml delete.yml read.yml update.yml ``` This will load mocks for `MyApi::Client::Customer, MyApi::Client::User, MyOtherApi::Client::Order, and MyOtherApi::Client::Invoice` The mock files are grouped by action, but you can name them anything and they will be accessible by this actions(shown later). **currently only YAMl files are accepted, with JSON coming soon.** #### Mock File Structure The file structure for each mock file is: ```yaml # user/create.yml : conditions: name: 'test_uers' response: id: 1 name: 'test_uers' ``` Example: ```yaml # my_api/users/create.yml test_user: conditions: name: 'test_uers' contact: 'test user' email_address: 'test@test.com' phone_number: '2062222222' address_id: nil credit_cards: [] address: address_line1: '111 test ave' addresS_line2: '' city: 'Seattle' state: 'WA' count: nil postal_code: '98109' results: id: 1 name: 'test_uers' contact: 'test user' email_address: 'test@test.com' phone_number: '2062222222' address_id: nil credit_cards: [] address: id: 1 address_line1: '111 test ave' addresS_line2: '' city: 'Seattle' state: 'WA' count: nil postal_code: '98109' ``` **Note:** MockingBird looks for `conditions:` and `:results` to set up the mocks properly. It will fail without them. #### Building the mocks Setting up the mocks is done by calling ```ruby MockingBird::setup_mocks(:path => Rails.root.join('test','mocks') ``` #### Fetching mock data Fetching the conditions and results you've set up is done by calling on MockingBird::Mocker: ```ruby # get the test user mock MockingBird::Mocker.my_api.user.create.test_user # Hash (2 element(s)) # conditions => - your conditions for test_user in create.yml file # results => - your results for test_user in create.yml file MockingBird::Mocker.my_other_api.invoice.create.invoice_1 ``` ## Contributing 1. Fork it ( https://github.com/[my-github-username]/mocking_bird/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request ======= mocking_bird ============ Mock manager for json_api_client_mocks