...includes a way to see what an e-mail will look like. Integration to RSpec All you need to do is implement a preview-class in spec/mailers/previews/notifier_preview.rb: class NotifierPreview < ActionMailer...
after_save { byebug if $debug; nil } def lock self.locked = true save end end Rspec.describe User do let(:user) { create(:user) } before do # Many users are created and saved in...
...marked_for_destruction?).sum(&:amount) end end How to test the correct behaviour in rspec it 'ignores invoice items marked for destruction in a nested update' do invoice = Invoice.make
So you are comparing two Time objects in an RSpec example, and they are not equal, although they look equal: expected: Tue May 01 21:59:59 UTC 2007,
...know that you did not break anything. Prefer "big picture" integration-like tests (using RSpec) over unit tests. Acceptance and manual testing As early as possible, take actual time to...
...of the application. For alternatives see Cucumber: Testing file downloads with Selenium. Usage in RSpec feature specs Copy the DownloadHelpers module to spec/support. You can now include the helper in...
...all your feature specs: RSpec.configure do |config| config.include(DownloadHelpers, type: :feature) end Usage in Cucumber scenarios Copy the DownloadHelpers module to features/support. Then include the helper in your scenarios and...
Helpers # performance_steps.rb # Cucumber steps for performance testing # Can easily be converted to an RSpec helper Given(/^I throttle the test browser I\/O to (\d+)kbps$/) do |kbps|
...DatabaseCleaner configured to take care of not bloating your test database with old records: RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:deletion) end config.before(:each) do DatabaseCleaner.strategy = :transaction
...migration database. This means we can now specify this second database when using DatabaseCleaner: RSpec.configure do |config| config.before(:suite) do DatabaseCleaner[:active_record].clean_with(:deletion) DatabaseCleaner[:active_record, db...
...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 models have validations for...
Simply add this to your .rspec instead: --require spec_helper If you are on rspec >= 3 and use a rails_helper.rb require this instead of the spec_helper: --require rails_helper...
...If you are using parallel_tests and this is not working for you, .rspec might be ignored. Try using a .rspec_parallel file...
...API from the example (skip this variant for the "upcoming movie" exercise) Use plain RSpec mocks ("stubs") to replace the HTTP request to the API with scripted behavior. Can you...
...only set this if you use a light terminal theme Improving Diffs for Ruby, RSpec and Cucumber files See Rails developers: Have better context in Git diffs. This will correctly...
...s poster as a file attachment to the e-mail? Can you write a RSpec test for this? In the lesson Form Models we said that we don't like...
...works in weird ways. Use the allow_value matcher instead: describe Email, '#sender' do # > Rspec 3 should syntax it { should allow_value("email@addresse.foo").for(:sender) } it { should_not allow_value...
...foo").for(:sender) } # Rspec 3 expect syntax it { is_expected.to allow_value("email@addresse.foo").for(:sender) } it { is_expected.not_to allow_value("foo").for(:sender) } end Errors that may occur if you do...
...to fix these errors in development instead of ignoring these in the logs. For RSpec you might want to use allow(ActionController::Parameters).to receive(:action_on_unpermitted_parameters).and...
Currently we often use geordi to run cucumber and rspec tests. Geordi takes care of installing a matching chromedriver for the installed google-chrome binary. The google-chrome binary is...
Please note that the changed behavior can also be observed in Capybara's RSpec matchers like have_text...
...name, like "Europe/Berlin" or "Asia/Tokyo". page.driver.browser.execute_cdp('Emulation.setTimezoneOverride', timezoneId: iana_zone_name) end end RSpec.configure do |config| config.include(TimeZoneHelpers, type: :feature) config.after(type: :feature, js: true) do set_browser_time...
...yet. Otherwise you could resize your window before every example just to be sure: RSpec.configure do |config| config.before(type: :feature) do case Capybara.current_driver when :desktop resize_browser_to(DESKTOP...
...on how to migrate legacy approaches to assignable_values. Testing There is a custom RSpec matcher...
...file type and adjust the code template according to your preferences. For example, the RSpec code template generates way too much boilerplate. Something like this is far more suitable for...
...following test was taken from a project using ActionDispatch::IntegrationTest. Though we usually use RSpec, this should give you the general idea. context 'favicons' do def link_selectors [ ['link[href...
...the console IRB. console command: Ctrl + C now properly exits a local Rails console rspec and cucumber commands: Run specs even if the automatic chromedriver update fails Improve detection of...
...instructions in the README. Most likely you want: to add the Ruby, Rails and RSpec cops to include the unit test 2. Report all existing offenses and exclude them initially...