Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/technicalpickles/file_fixture
A helper method for loading files during test
https://github.com/technicalpickles/file_fixture
Last synced: about 1 month ago
JSON representation
A helper method for loading files during test
- Host: GitHub
- URL: https://github.com/technicalpickles/file_fixture
- Owner: technicalpickles
- License: mit
- Created: 2008-07-14T00:07:27.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2008-07-14T15:18:44.000Z (over 16 years ago)
- Last Synced: 2024-10-14T21:52:56.037Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 78.1 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
README
# file\_fixture
## Installing
gem install technicalpickles-file_fixture -s http://gems.github.com
## Usage
file\_fixture provide provides a convenience method for loading data from files. To use, you just add the snippet to your `test_helper.rb`:
require 'file_fixture/test_unit'
FileFixture::FIXTURE_DIR = File.join(File.dirname(__FILE__), "file_fixtures")Place files into the `file_fixtures` directory, and then you can use `file_fixture 'foo'` to read and return `file_fixtures/foo`.
If you were building wrappers around web APIs, you should use static data instead of hitting the API directly. We can use file_fixture to implement this helper method:
def stubbing_http_response_with_fixture(file)
response = stub(:body => file_fixture(file), :value => nil)
Net::HTTP.any_instance.stubs(:request).returns(response)yield
endYou could then use this in tests like:
stubbing_http_response_with_fixture('get_tags.xml') do
assert_equal 6, @user.tags.size # @user.tags does a HTTP request
end## License
See LICENSE