...testing e.g. that a file user_export.xlsx is written to disk (smoke test) end end RSpec setup RSpec setup that avoids rewriting your scripts in a special way to make them...
stub_const('ARGV', args.map!(&:to_s)) load(script_path, true) end end RSpec.configure do |config| config.define_derived_metadata(file_path: Regexp.new('/spec/script')) do |metadata| metadata[:type] = :script
...run specs in the exactly same order like in the CI. Example for running rspec 3/8 with a seed output of 20689: CI_NODE_INDEX=2 CI_NODE_TOTAL...
...bundle exec rake "knapsack:rspec[--seed=20689]" Note: the environment variable CI_NODE_INDEX starts at 0 As an alternative you can copy and paste the test files from both...
As we are slowly switching from Cucumber scenarios to RSpec feature specs, you might be tempted to write assertions like this one: feature 'authorization for cards management' do
...behavior is that the Capybara test server is running in another thread, and the RSpec thread can't "see" the exception at this point in time. As we are emulating...
...or change the encoding. This is all possible, look up for the proper options. RSpec We used this helper in some project to do not have to write comma separated...
file end def generate_empty_csv file = Tempfile.new file.write(' ') file.rewind file end end RSpec.configure do |c| c.include CsvHelpers end The you can generate a csv file like this:
...enable the polling feature for the one E2E test that tests polling. In an RSpec request spec this would look like this: scenario 'The project list is updated periodically' do...
...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...
...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...
...to grab both the key and value from a hash Rerun Only Failures With RSpec RSpec can be configured to run only failed specs: RSpec.configure do |config| config.example_status_persistence...
...file_path = "tmp/failed_specs.txt" end # Then, run "rspec --only-failures" Disassemble Some Codes RubyVM::InstructionSequence#compile can be used to compile Ruby code on the fly. It offers a #disasm method...
...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...
...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'
...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...
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...
...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...
...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...
...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...
...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|