How to configure # in ~/.gitattributes: *.rb diff=ruby *.rake diff=ruby *_spec.rb diff=rspec *.feature diff=cucumber Then tell Git where it can find its global attributes file with...
...this on a per-project base as well.) Ruby support is built in, but RSpec and Cucumber need a little more help: # in ~/.gitconfig [diff "rspec"] xfuncname = "^[ \t]*((RSpec|describe...
...p and following the guidelines from the referred card above. If you are debugging rspec tests, you can use rspec -b to print the full stack trace. If you encounter...
...local Rails server's log ..or tail -f log/test.log to see the same for RSpec tests! Different debugging libraries Ruby has always had multiple gems for debugging. When you're...
...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
...runners like in the following example .gitlab-ci.yml: rubocop: interruptible: true script: - 'bundle exec rubocop' rspec: interruptible: true script: - 'bundle exec rspec' Afterwards new pushes to your MR will cancel all...
...und Nachteile von integration tests? Wann bringt man was zum Einsatz? Lerne Tests mit RSpec zu schreiben Verstehe welche Nachteile entstehen wenn man zu viel testet Tests schreiben kostet Zeit...
...sind weitere Tests nicht mehr so nützlich (teilw. Überschneidung von Tests) Lerne wie du RSpec einsetzt um deine Scripts zu testen Inhalte Writing basic tests with Rspec Rspec Dokumentation
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...
...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 only)
...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...
...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...
...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...
...just say create(:movie) instead of FactoryBot.create(:movie). You can configure this like so: RSpec.configure do |config| config.include FactoryBot::Syntax::Methods end Also see RSpec: Where to put custom matchers...
...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...
...file uploads with Rails Carrierwave: How to attach files in tests Carrierwave: Built-in RSpec matchers CarrierWave: Processing images with libvips Multipart formposts Content Disposition Header Exercise In MovieDB, allow...
Rendering of image versions and validation of file extension can be tested with RSpec These can be model specs for either the Movie or your PosterUploader
...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'
...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...
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...
...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...
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...
...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