Skip to content

Commit

Permalink
update readme to nudge towards nix
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelglass committed Nov 13, 2024
1 parent 01c7152 commit 71a8631
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# RailsEdgeTest

There is a particular type of integration testing that we have found very fruitful. We:
- load up our front-end with its virtual dom,
- assert expectations by querying the virtual dom, and
- load up our front-end with its virtual dom,
- assert expectations by querying the virtual dom, and
- interact with our application by simulating events on elements in the virtual dom

We have found these browser-less integration tests to be orders of magnitude faster than typical capybara integration tests, with minimal downsides. One of the biggest drawbacks to this approach is that we must maintain the json we expect from the backend in a form that is available to these tests, typically a json file (or Elm file with a json blob). Maintaining the blob causes two problems:
1. The blob can easily become out-of-sync with our backend, and
1. The blob can easily become out-of-sync with our backend, and
2. There is no specification for how to recreate it when things do become out-of-sync.

This gem aims to solve these problems. The rails_edge_test gem allows us to:
- use Ruby code to explicitly specify each json blob our front-end tests require,
- use Ruby code to explicitly specify each json blob our front-end tests require,
- re-generate these files, as needed, with a simple rake task.

We write what we call "edge specs," Ruby files that specify the json edge between our front- and back-end by using our Rails models and controller actions directly. These are written using a DSL evocative of an RSpec spec. They allow us to generate json blob files which we commit to our repo, and access from our front-end integration tests. Over time, as our APIs develop, we can simply rerun our edge specs in order to update these json blobs based on existing specifications.
Expand Down Expand Up @@ -44,22 +44,22 @@ include RailsEdgeTest::Dsl
controller HomeController do
action :show do
let(:user) { create :user }

edge "first time user" do
user
perform_get

# generates Edge.HomeController.Show.FirstTimeUser with `json` function
produce_elm_file('FirstTimeUser')
produce_elm_file('FirstTimeUser')
end

edge "returning user" do
user
create :post, user: user
perform_get

# generates Edge.HomeController.Show.ReturningUser with `json` function
produce_elm_file('ReturningUser')
produce_elm_file('ReturningUser')
end
end
end
Expand Down Expand Up @@ -122,19 +122,35 @@ require Rails.root.join('edge', 'spec', 'edge_helper')

## Development

This project uses nix to manage the dev environment.

This project additionally uses
- [direnv](https://github.com/direnv/direnv)
- flakes

If you don't have flakes enabled, you can enable them by adding `experimental-features = flakes` to your `~/.config/nix/nix.conf` file.
(or running )

typing `direnv allow` loads the dev environment including a compatible ruby, sqlite, and gems.

To modify gem dependencies, use the bundle wrappers
- `bundle-lock` to update the lockfile
- `bundle-update` to update gems & the lockfile
then run `bundix` to update the `gemset.nix` file.

### Usage Without Nix

Usage without nix is unsupported but may work anyways. Try the following:

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`.

To release a new version, follow the instructions in [PUBLISHING.md](PUBLISHING.md).

### Nix support
Note: We only support adding gems and dependencies using nix.

In order to get Nix working you need to have [direnv](https://github.com/direnv/direnv) installed. You will have to `direnv allow` to load the current `.envrc`. You can then run from the top level folder:
### Publishing

```
./nix/update-gemset.sh
```
To release a new version, follow the instructions in [PUBLISHING.md](PUBLISHING.md).

## Contributing

Expand All @@ -144,4 +160,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/NoRedI
## License

The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

0 comments on commit 71a8631

Please sign in to comment.