CrossSpec
A utility library for marking cross app testing easier with tools for distributed factories, test parallelism, and verification of async events.
Installation
Add this line to your application's Gemfile:
gem 'cross_spec'
And then execute:
$ bundle
Usage
Listen for service requests in your app
CrossSpec.handle("app1:create_user") do
# create a user in here
# then tell the spec that the data is ready
CrossSpec.beacon("app1:user_created", {id: 123})
end
CrossSpec.listen! # blocks forever
Notify of side effects in your app
CrossSpec.beacon("app1:background_job1_success")
Notify of failures in your app
CrossSpec.failure_beacon!
Ask for data in a spec and wait for it
CrossSpec::Spec.trace do
user = sync(service: "app1:create_user", {email: "[email protected]"}, tasks: "app1:user_created")
user["id"] # 123
end
Ask for data in a spec async and wait for it later
CrossSpec::Spec.trace do
async(service: "app1:create_user", {email: "[email protected]"})
async(service: "app2:create_blogpost", {title: "Read me"})
# keep doing things if you want ...
# block until the data is all ready
user, blogpost = await(tasks: ["app1:user_created", "app2:blogpost_created"])
end
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bundle exec rspec
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cross_spec.
License
The gem is available as open source under the terms of the MIT License.