<commit_before>ActiveresourceHttpmockRecord
============================

Testing models which communicate with remote web services could be painful.
This gem provides a simple way to record HTTP request and response through ActiveResource, and playback with ActiveResource::HttpMock.

Features
--------

If your application uses ActiveResource:

* ActiveresourceHttpmockRecord works together with your test code, records HTTP requests generated by an ActiveResource model and HTTP response coming from the remote web service.
  * They're stored as YAML files to play back later
* During the same test code runs after that, ActiveresourceHttpmockRecord mocks HTTP requests and responses recorded istead of creating new actual HTTP sessions with ActiveResource.


Supported testing tool
----------------------

* RSpec


Installation
------------

Add this line to your application's Gemfile:

    gem 'activeresource_httpmock_record'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install activeresource_httpmock_record


Usage
-----

### RSpec

You may write your spec like:

```ruby
describe User do
  subject(:user) { User.find(1) }

  it 'has a name' do
    expect(user.name).to be_present
    expect(user.name).to be_a(String)
  end
end
```

When running it, ```User.find(1)``` causes a HTTP request.

To activate ActiveresourceHttpmockRecord, add a metadata hash ```httpmock: <file_name>``` to groups or examples in your spec.

```ruby
describe User do
  subject(:user) { User.find(1) }

  it 'has a name', httpmock: a_user do
    expect(user.name).to be_present
    expect(user.name).to be_a(String)
  end
end
```

Once you run the spec, ActiveresourceHttpmockRecord record HTTP request and response as a ```a_user.yml```, and if you run it again, ActiveresourceHttpmockRecord load the HTTP session from ```file_name.yml``` and mock it for you.


#### Warning

ActiveresourceHttpmockRecord doesn't support a multi-threaded testing like Capybara with ```js: true``` option.


Configuration
-------------

You can change the mock file store by adding the following lines (typically ```spec_helper.rb``` for RSpec):

```ruby
ActiveResourceHttpMock.configure do |config|
  config.httpmock_path = '/path/to/directory'
end
```


Contributing
------------

1. Fork it
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 new Pull Request<commit_msg>Mention the default mock storage path<commit_after>ActiveresourceHttpmockRecord
============================

Testing models which communicate with remote web services could be painful.
This gem provides a simple way to record HTTP request and response through ActiveResource, and playback with ActiveResource::HttpMock.

Features
--------

If your application uses ActiveResource:

* ActiveresourceHttpmockRecord works together with your test code, records HTTP requests generated by an ActiveResource model and HTTP response coming from the remote web service.
  * They're stored as YAML files to play back later
* During the same test code runs after that, ActiveresourceHttpmockRecord mocks HTTP requests and responses recorded istead of creating new actual HTTP sessions with ActiveResource.


Supported testing tool
----------------------

* RSpec


Installation
------------

Add this line to your application's Gemfile:

    gem 'activeresource_httpmock_record'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install activeresource_httpmock_record


Usage
-----

### RSpec

You may write your spec like:

```ruby
describe User do
  subject(:user) { User.find(1) }

  it 'has a name' do
    expect(user.name).to be_present
    expect(user.name).to be_a(String)
  end
end
```

When running it, ```User.find(1)``` causes a HTTP request.

To activate ActiveresourceHttpmockRecord, add a metadata hash ```httpmock: <file_name>``` to groups or examples in your spec.

```ruby
describe User do
  subject(:user) { User.find(1) }

  it 'has a name', httpmock: a_user do
    expect(user.name).to be_present
    expect(user.name).to be_a(String)
  end
end
```

Once you run the spec, ActiveresourceHttpmockRecord record HTTP request and response as a ```a_user.yml```, and if you run it again, ActiveresourceHttpmockRecord load the HTTP session from ```file_name.yml``` and mock it for you.


#### Warning

ActiveresourceHttpmockRecord doesn't support a multi-threaded testing like Capybara with ```js: true``` option.


Configuration
-------------

You can change the mock file store by adding the following lines (typically ```spec_helper.rb``` for RSpec):

```ruby
ActiveResourceHttpMock.configure do |config|
  config.httpmock_path = '/path/to/directory'
end
```

The default store is 'spec/fixtures/httpmock'.


Contributing
------------

1. Fork it
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 new Pull Request
{'fraction_non_alphanumeric': 0.11431372549019608, 'fraction_numerical': 0.003137254901960784, 'mean_word_length': 3.966893865628043, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6139616', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1387, 'n_words': 595}