...in this case, and you will see less noise in your test output: if RSpec.configuration.files_to_run.count > 5 require "simplecov" SimpleCov.start 'rails' end See also How to use Simplecov to find untested...
...code in a Rails project with RSpec and Cucumber
Simply load the TimeHelpers module as required by your test framework. Example: RSpec.configure do |config| config.include ActiveSupport::Testing::TimeHelpers end Comparison to Timecop Timecop allows you to choose...
...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...
...If you access Redis in tests, I suggest introducing a helper method. Example for RSpec: module RedisHelpers def redis @redis ||= Redis.new(url: REDIS_URL) end end RSpec.configure do |config| config.include...
...good reason) not rendered in controller specs. If you need it to happen, use: RSpec 1 (Rails 2): integrate_views RSpec 2 (Rails 3): render_views Note that you can...
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...
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,
...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
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|
...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...
...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...
...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...
...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...
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...
...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...
...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...
Please note that the changed behavior can also be observed in Capybara's RSpec matchers like have_text...
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...
...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...
...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...
...the rerun, but we'll lose that in the future anyways when migrating to RSpec
...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...
...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...