This document describes how to run tests for the Volley Ruby SDK.
- Install dependencies:
bundle install- Ensure RSpec is installed (included in dev dependencies):
bundle exec rspec --versionUnit tests use mocked HTTP responses with WebMock and don't require a real API token:
bundle exec rspec spec/Or run specific test files:
bundle exec rspec spec/volley_client_spec.rb
bundle exec rspec spec/organizations_resource_spec.rbIntegration tests make real API calls to the Volley API. These tests are skipped unless VOLLEY_API_TOKEN is set.
To run integration tests:
- Set your API token:
export VOLLEY_API_TOKEN=your-api-token-here- Run integration tests:
bundle exec rspec spec/integration_spec.rbNote: Integration tests may create, modify, or delete resources in your account. Use a test account or be prepared to clean up test data.
To run all tests (unit and integration):
bundle exec rspecTo generate a test coverage report, you can use SimpleCov:
- Add SimpleCov to your Gemfile:
group :test do
gem 'simplecov', require: false
end- Add to
spec/spec_helper.rb:
require 'simplecov'
SimpleCov.start- Run tests:
bundle exec rspecCoverage reports will be generated in the coverage/ directory.
Unit tests should mock HTTP responses using WebMock:
require 'webmock/rspec'
RSpec.describe Volley::VolleyClient do
it 'makes successful request' do
stub_request(:get, 'https://api.volleyhooks.com/api/org')
.with(headers: { 'Authorization' => 'Bearer test-token' })
.to_return(status: 200, body: '{"id": 1, "name": "Test"}')
client = Volley::VolleyClient.new('test-token')
response = client.request('GET', '/api/org')
expect(response['id']).to eq(1)
end
endIntegration tests should:
- Check for
VOLLEY_API_TOKENenvironment variable - Skip if not set
- Clean up any resources created during tests
- Use descriptive test names
Example:
RSpec.describe 'Integration Tests', type: :integration do
let(:api_token) { ENV['VOLLEY_API_TOKEN'] }
let(:client) { Volley::VolleyClient.new(api_token) if api_token }
before do
skip 'VOLLEY_API_TOKEN environment variable is not set' unless api_token
end
it 'lists organizations' do
orgs = client.organizations.list
expect(orgs).to be_a(Array)
end
endThe SDK includes RSpec configuration that can be used in CI/CD pipelines. The configuration:
- Runs all tests in the
spec/directory - Excludes integration tests by default (unless
VOLLEY_API_TOKENis set) - Uses documentation format for better output
To check code style:
bundle exec rubocopTo auto-fix issues:
bundle exec rubocop -a