...k] + (f * (values_sorted[k + 1] - values_sorted[k])) end benchmarks = [ %(User.where('name ILIKE ?', '%test%').first), %(User.where('email ILIKE ?', '%test%').first), ] measurements = benchmarks.index_with do |_benchmark| [] end benchmarks.each do |benchmark...
View specs are a powerful tool to test several rendering paths by their cases instead of using a more costing feature spec. This is especially useful because they become quite...
...the view independent from the controller-logic. Therefore it will be more applicable to test views within request specs. But, even then, you still can use Caypbara's matchers within...
When you find similar groups of expect calls in your tests, you can improve readability by extracting the group into its own matcher. RSpec makes this easy by allowing matchers...
...to call other matchers. Example The following test checks that two variables foo and bar (1) have no lowercase characters and (2) end with an exclamation mark: expect(foo).to...
The idea is this: you take a job that you'd rather not do manually, and describe it to babushka...
If a project ist configured to spawn CI runners for tests or deployment when pushing to the Repo, a habit of pushing WIP commits regularly may conflict with that.
...trashed_changed? end Or, move the conditions into the callback. This also allows you test the conditions more easily using a unit test: after_save :update_offices_people_count
if office_id_changed? || trashed_changed? ... end end Also see the card on testing conditional validations...
...serve requests with the HOST header hacker.xyz You need to take care in your tests, that you reset ActionMailer::Base.default_url_options after e.g. request specs, e.g. spec/support/action_mailer.rb: RSpec.configure do...
...should be ignored and no validation errors should be shown. Make sure to write tests for the showtimes form. How do you refer to the showtimes fields when there are...
...must not contain any code or names specific to movies or the movie form. Test that the component is reusable by allowing to add an actor's roles from within...
...number of words, lines and paragraphs, and outputs the result. For example: $ ruby count_words.rb test.txt test.txt has 123 words test.txt has 13 lines test.txt has 4 paragraphs Hint
...main').search('horizon').where('year > 1995').order(:year).to_a Adapt both the integration test and RSpec examples for the search functionality, using the guidelines from the "Testing" chapter in...
...Growing Rails Applications in Practice. RSpec examples should cover all edge cases E2E tests should only cover one "happy path" to show successful integration Open budgets in Project Hero (makandra...
...verification") added without_partial_double_verification. This might be handy in case you are testing helpers in Rails, where you sometimes rely on methods defined in the application controller (e.g...
...module UsersHelper def user_display_name [current_user.first_name, current_user.last_name].join(' ') end end Unit test with error describe UsersHelper do describe '#user_display_name' do it 'returns the first and...
...follow this workflow. Finishing a feature When you're done with your feature and tests are green, and your changes pass our merge request checklist: Within your feature branch, merge...
The argument that using tests is a ideologic waster of time fails when one considers how it can help to insure architectural decisions...
I brought up the question whether tests should call the translation API when checking for the presence of a string...
Unit tests are to refactoring like a drop cloth is to painting. Both feel like more work at first but ultimately save you time by allowing you to move faster...
...no way to do it in Capybara, unfortunately. But if you're running your tests with the Selenium driver (and probably other drivers that support JavaScript), you can hack it
...instead reference another part of that email by a content ID cid:xxxxx@xxxxx.mail. Your tests will not be able to verify easily that you used the correct image version any...
...last point, it is recommended to use a feature flag and disable inlining in tests by default so you will still be able to easily test that your emails use...
SMTP validation: connects to the host received from DNS and starts a test delivery to find out if the recipient mailbox actually exists tl;dr: We suggest you...
...and expected constants are resolved: class_name = params[:type].presence_in(%w[User Post Test]) if class_name class_name.safe_constantize.new # either User, Post or Test else Rails.logger.error "This should not happen...
This rule needs to be adapted to your setup and needs to be tested before it's activated. Activating lifecycle rules can instantly delete images from registries.
"tagStatus": "tagged", "countType": "sinceImagePushed", "countUnit": "days", "countNumber": 10 }, "action": { "type": "expire" } } ] } Careful when testing Testing these rules is a little confusing because of the wording in the AWS console...
...should have an overview which kinds of validations are built into Rails. Also read Testing ActiveRecord validations with RSpec. Make the following changes to your MovieDB: Make sure your MovieDB...
...for black and white movies and release_year >= 1917 for color movies. Add tests for your validation. Make sure you have a test for each case...
Your development machine is usually on a very good network connection. To test how your application behaves on a slow network (e.g. mobile), you can simulate limited bandwidth. Chrome
...change this attribute to hold a list of URLs, and need to adjust all tests. Our goal is to convert the url "..." to the urls ["..."] here. Open find and replace...
...geordi png-optimize Carrierwave Go through our Carrierwave checklist if used. Maintenance Integrate and test the capistrano maintenance task. Accessibility Decide what effort you want to put in improving accessibility...