...exceptions (previous default behavior, value false) Using the new default needs to change a RSpec test like this: Before it 'raises an exception if the page could not be found...
...need to check the underlying exception, you can temporary change the show_exception setting: RSpec.configure do |config| config.around(:each, :show_exceptions) do |example| show_exceptions = Rails.application.env_config['action_dispatch.show_exceptions'] Rails.application.env...
...install the socat package) Start you integration test e.g. REMOTE_DEBUGGING=1 bundle exec rspec spec/system/some_spec.rb with a debugger set Open chrome://inspect/. It should list the test Chrome under...
...don't run the super method inside #initialize, the object is marked as frozen. Rspec mocks (e.g. using partial doubles with receive(partial_double).to ...) in tests would raise...
...the following error (just imagine how hard debugging can be): ArgumentError: Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations. If you define initialize with...
...tests, that you reset ActionMailer::Base.default_url_options after e.g. request specs, e.g. spec/support/action_mailer.rb: RSpec.configure do |config| config.around(type: :request) do |example| url_options = ActionMailer::Base.default_url_options.dup example.run ActionMailer::Base.default_url...
...specs to pass. This way we see Jasmine failures in our regular test runs. RSpec In a feature spec you can run Jasmine specs like this: scenario 'Jasmine tests' do...
...groups, are only excluded, when both of the groups are excluded, e.g. to exclude rspec in the following example, you will have to bundle without test and cucumber:
gem 'rspec'
find('.test2', visible: :hidden) finds the .test2 element As an example, an RSpec test which tries to confirm an element exists but is currently not visible, would say...
...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...
...screenshot can automatically save screenshots and the HTML for failed Capybara tests in Cucumber, RSpec or Minitest. Requires Capybara-Webkit, Selenium or poltergeist for making screenshots. Screenshots are saved into...
...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...
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...
...file_fixture is not available by default. To enable it, include a support module from rspec-rails: FactoryBot::SyntaxRunner.include(RSpec::Rails::FileFixtureSupport) That includes ActiveSupport::Testing::FileFixtures, where file_fixture...
...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...
...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...
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|
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...
...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...