All Projects → amatsuda → Still_life

amatsuda / Still_life

Licence: mit
Rails upgrade's best friend

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Still life

Rails new
A thoughtfully designed template for building modern Rails apps. Get started in minutes instead of hours 🔥🚀
Stars: ✭ 151 (-29.11%)
Mutual labels:  ruby-on-rails, rspec
Action Cable Testing
Action Cable testing utils
Stars: ✭ 192 (-9.86%)
Mutual labels:  rspec, minitest
Vscode Ruby Test Adapter
A Ruby test adapter extension for the VS Code Test Explorer
Stars: ✭ 50 (-76.53%)
Mutual labels:  rspec, minitest
Factory trace
Simple tool to maintain factories and traits from FactoryBot
Stars: ✭ 184 (-13.62%)
Mutual labels:  rspec, minitest
With model
Dynamically build an Active Record model (with table) within a test context
Stars: ✭ 119 (-44.13%)
Mutual labels:  rspec, minitest
Knapsack
Knapsack splits tests evenly across parallel CI nodes to run fast CI build and save you time.
Stars: ✭ 430 (+101.88%)
Mutual labels:  rspec, minitest
Email Spec
Collection of RSpec/MiniTest matchers and Cucumber steps for testing email in a ruby app using ActionMailer or Pony
Stars: ✭ 1,142 (+436.15%)
Mutual labels:  rspec, minitest
LocalSupport
A directory of local support services and volunteer opportunities
Stars: ✭ 60 (-71.83%)
Mutual labels:  rspec, ruby-on-rails
Rails Testing Toolbox
🔧 Tools to help Rails developers test
Stars: ✭ 110 (-48.36%)
Mutual labels:  ruby-on-rails, rspec
Fake ftp
A fake FTP server for use with ruby tests
Stars: ✭ 77 (-63.85%)
Mutual labels:  rspec, minitest
N plus one control
RSpec and Minitest matchers to prevent N+1 queries problem
Stars: ✭ 345 (+61.97%)
Mutual labels:  rspec, minitest
Websiteone
A website for Agile Ventures
Stars: ✭ 132 (-38.03%)
Mutual labels:  ruby-on-rails, rspec
Everydayrails Rspec 2017
Sample source for the 2017 edition of Everyday Rails Testing with RSpec.
Stars: ✭ 280 (+31.46%)
Mutual labels:  ruby-on-rails, rspec
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+322.54%)
Mutual labels:  rspec, minitest
factory bot-preload
Preload factories (factory_bot) just like fixtures. It will be easy and, probably, faster!
Stars: ✭ 68 (-68.08%)
Mutual labels:  rspec, minitest
Pig Ci Rails
Monitor your Ruby Applications metrics (Memory, SQL Requests & Request Time) as part of your test suite.
Stars: ✭ 53 (-75.12%)
Mutual labels:  ruby-on-rails, rspec
souls
SOULs 🔥 Build Serverless Apps faster like Rails. Powered by Ruby GraphQL, RBS/Steep, Active Record, RSpec, RuboCop, and Google Cloud.
Stars: ✭ 327 (+53.52%)
Mutual labels:  rspec, ruby-on-rails
knapsack pro-ruby
Knapsack Pro gem splits tests across parallel CI nodes and makes sure that tests will run in optimal time on each node.
Stars: ✭ 101 (-52.58%)
Mutual labels:  rspec, minitest
Ifme
Free, open source mental health communication web app to share experiences with loved ones
Stars: ✭ 1,147 (+438.5%)
Mutual labels:  ruby-on-rails, rspec
Lurker
📖 The ultimate tool for documenting and testing APIs in Rails
Stars: ✭ 120 (-43.66%)
Mutual labels:  rspec, minitest

still_life

What's This?

still_life is a testing framework enhancements for test-unit, minitest, RSpec, and Capybara that records all HTML response body texts that are rendered during E2E or unit test executions.

So What?

You can compare actually rendered HTML results before and after any app updates.

For What?

By comparing all these HTML files that are processed before and after any kind of code change, you can make sure that you did not (or you did) introduce any new user-facing incompatibilities. This may greatly help you for example, refactoring your app, replacing external libraries, or upgrading libraries. My personal use case that made me gemifying still_life was that I wanted to make sure that my own template engine renders the same HTML as the one that I was using.

But indeed, the real sweet spot of this tiny library is IMO "Rails upgrade". In fact, The first original version of this tool was implemented as an RSpec monkeypatch while we were upgrading a huge Rails application from Rails 2 to Rails 3.

Installation

Bundle still_life gem to your Rails app's :test environment.

gem 'still_life', group: :test

Usage

Run tests with an envvar STILL_LIFE. Then still_life creates some HTML files under tmp/html/#{ENV['STILL_LIFE']}/ directory. Each .html file is named from the location in your test code where the request was made.

For instance, if you run the tests against a simple scaffold app, the generated files will be like this:

% STILL_LIFE=rails52 rails test:system test
% tree tmp/html
tmp/html
└── rails52
    └── test
        ├── controllers
        │   ├── users_controller_test.rb-14.html
        │   ├── users_controller_test.rb-20.html
        │   ├── users_controller_test.rb-27.html
        │   ├── users_controller_test.rb-32.html
        │   ├── users_controller_test.rb-37.html
        │   ├── users_controller_test.rb-43.html
        │   └── users_controller_test.rb-9.html
        └── system
            ├── users_test.rb-14.html
            ├── users_test.rb-18.html
            ├── users_test.rb-21.html
            ├── users_test.rb-25.html
            ├── users_test.rb-26.html
            ├── users_test.rb-29.html
            ├── users_test.rb-32.html
            ├── users_test.rb-36.html
            ├── users_test.rb-37.html
            └── users_test.rb-9.html

4 directories, 17 files

And each file content is just an HTML.

% cat tmp/html/rails52/test/system/users_test.rb-18.html
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
    <title>StillLifeTest</title>
    
    

    <link rel="stylesheet" media="all" href="/assets/application-35729bfbaf9967f119234595ed222f7ab14859f304ab0acc5451afb387f637fa.css" data-turbolinks-track="reload" />
    <script src="/assets/application-3c2e77f06bf9a01c87fc8ca44294f3d3879d89483d83b66a13a89fc07412dd59.js" data-turbolinks-track="reload"></script>
  </head>

  <body>
    <p id="notice">User was successfully created.</p>

<p>
  <strong>Name:</strong>
  MyString
</p>

<a href="/users/980190963/edit">Edit</a> |
<a href="/users">Back</a>

  

</body></html>

Usage Scenario

Consider you have a well-tested Rails 5.2 app, and you want to upgrade its Rails version to 6.0 without introducing any user-facing incompatibilities. Then the workflow will be as follows:

1. Draw a still_life with the 5.2 app

% STILL_LIFE=rails52 rails test:system test

2. Do the upgrade job

% bundle u
% rails app:update

and push some more commits...

3. Draw another still_life with the 6.0 app

% STILL_LIFE=rails60 rails test:system test

4. Compare the results, and make sure there's no unexpected diffs

% git diff --no-index --color-words tmp/html/rails52/ tmp/html/rails60/

Notes

git diff

As written in the above example, git diff --no-index --color-words should perfectly work for recursively comparing two output directories.

Random Values

If your response includes some kind of random values, the test results may change between each test runs. In such case, maybe you could specify a random seed, or mock the random source in your app.

TODOs / Known Issues

  • The Capybara monkeypatch sometimes fails to get the page.body due to Capybara timing problem
  • Support older versions of Rails, Capybara, and Ruby
  • Fix the CI with RSpec + headless Chrome

Contributing

Pull requests are welcome on GitHub at https://github.com/amatsuda/still_life.

Credit

The original idea of this library was implemented as a 10 LOC anonymous module by @hotchpotch at Cookpad Inc. back in 2011 as written in this slide.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].