lib |
spec |
6d .gitignore |
6d CHANGELOG |
6d Gemfile |
6d Gemfile.lock |
6d LICENSE |
6d README.md |
6d deploy.rb |
6d lobbyist.gemspec |
You don't need this source code unless you want to modify the gem. If you just want to use the Lobbyist Ruby bindings, you should run:
gem install lobbyist
If you want to build the gem from source:
gem build lobbyist.gemspec
TODO: Get Documentation URL.
Please see ### API DOCUMENTATION URL ### for up-to-date documentation.
If you need to check for the presence of an object returned from Lobbyist you will need to check for the presence of an actual attribute. For example:
company = Lobbyist::V2::Company.find(10000) company.present? # This will always be true because 'company' is a valid Lobbyist object. # This is probably what you want. It checks that data was actually returned from the API. company.company_id.present?
If you would like to run the tests simply run rspec
in the root of the project.
Open coverage/index.html
to see a code coverage report generated from the test run.
The tests have been converted over to VCR. This makes the tests much easier to write and maintain. Check the official VCR gem for full documentation.
This will be a brief introduction to writing VCR tests for this project. Here is a sample from the company_spec.rb tests.
describe ':find' do it 'should fail with status 404 if the id is not valid' do VCR.use_cassette('company_find_error') do expect{Lobbyist::Company.find(1)}.to raise_error(Lobbyist::Error::NotFound) end end it 'should return the found company' do VCR.use_cassette('company_find') do company = Lobbyist::Company.find(127) expect(company).to_not be_nil expect(company).to be_a(Lobbyist::Company) expect(company.company_name).to eq('Customer Lobby') end end end
The first line in each test is VCR.use_cassette('...')
. The string provided is the name of
a file that VCR will use to simulate the remote call. If the file doesn't exit yet VCR will
actually call the remote API, get the results and use them to generate the fixture file. So the test
writing process goes something like:
There is no need to write complex mock statements. You write your test the way you normally would for
non-remote code, and just wrap that in a VCR.use_cassette('...') do end
block.
Keep in mind that because VCR hits the API for each cassette file you will need to have your development API server running and the data you pass must be valid data. In the example above, for example, the company_id that is passed to the find method actually exists in the database. For create and update tests you will also need to actually create a record and update an existing record.
If you would like to see the cassette files generated from your calls they are stored at spec/cassettes
.
There is a subdirectory for V2 based tests.
For projects that include Lobbyist as a gem, currently only the Members project, follow these steps to update the lobbyist-ruby gem.
lib/lobbyist.rb
with a require
statement for the new class.lib/lobbyist/version.rb
patch number. This is required for bundler to detect the update.Using the changes in the host project.
bundle update lobbyist-ruby
to force bundler to update the lobbyist gem.Now lobbyist-ruby needs to be updated on the gem host we use with Semaphore, Gemfury.
ruby deploy.rb