A comprehensive script to convert test suites from RSpec 2 to RSpec 3. This converts more than should/expect syntax...
To make the RSpec matcher of the authorization solution Consul work with Rspec 2.x read the following blog post...
...and_call_original object.should_receive(:some_method).with('my argument').and_return('other value') Requires rspec-mocks...
RSpec let's you chain a matcher with .or. The expectation will then pass if at least one matcher matches: expect(color).to eq("red").or eq("green")
...of awesome shell scripts, has been extended by three scripts to help you call RSpec or Cucumber: cuc This script runs Cucumber the way you want it: Prints some line...
...t wip features/users.feature # run one feature with parameters like cucumber rs This script runs RSpec the way you want it: Prints some line feeds to easily find your test results...
When you write a custom RSpec matcher a good place to store them is to create one file per matcher in spec/support/matchers: spec/support/matchers/be_same_numbers_as.rb spec/support/matchers/be_same_second_as.rb spec/support/matchers/exist_in_database.rb spec/support/matchers/include_hash.rb You can include all...
Hint: There's another card with this helper for Cucumber features. Sometimes you feel like you need to stub some...
...For this purpose the gem allows you to record execution time when you call rspec with --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log. As the documentation on this states you can...
...make this the default option by adding the following to your .rspec (or .rspec_parallel) file: --format progress --format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log Knapsack For knapsack to generate reports...
...cons of end-to-end tests ("E2E tests", "full-stack integration tests"). Learn basic RSpec for unit tests ("model specs") and E2E tests ("features") Learn to use Capybara to control...
...the implementation. Learn how to run tests in existing applications. Learn about Geordi's rspec and tests commands Learn when to write unit tests, when to write integration tests, when...
This raises "Could not find first Keyword": describe Keyword do it { should validate_uniqueness_of(:text) } end Do this instead...
...bash aliases helped me speed up that process: alias show-next-failure="bundle exec rspec --next-failure" alias open-next-failure="show-next-failure || show-next-failure --format json | jq...
...Define an alias to run the next failure alias show-next-failure="bundle exec rspec --next-failure" # IFF there is a failure, print it to the console, then
...test to ensure it works within your app. The test should fail: bundle exec rspec spec/requests/default_etag_spec.rb Fixing random CSP nonces Open config/initializers/content_security_policy.rb and change the content_security_policy_nonce_generator...
Checking successful integration The test we added earlier should now pass: bundle exec rspec spec/requests/default_etag_spec.rb To manually test ETags, open the Network tab of your DevTools. Then load the...
...have automated tests for all Ruby/Rails combinations as well. Tests usually live in spec/ (RSpec) or test/ (used by multiple test frameworks) or features/ (Cucumber). Most gems only need unit...
...tests (as they're code libraries, not applications) which we mostly write in RSpec. The test setups in our gems have evolved over time, and are a bit scattered at...
...your specs, please make sure that you have not introduced a flaky spec. Using RSpec matchers One rule of thumb I try to follow in capybara tests is using capybara...
...matchers and not plain rspec matchers. One example: visit(some_page) text_field = find('.textfield') expect(text_field['value']).to match /pattern/ This can work, but is too brittle and...
See the test failing Run the test to see it fail bundle exec rspec F Failures: 1) File "/entrypoint.sh" is expected to exist Failure/Error: it { should exist} expected File...
...seconds (files took 0.31723 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/dockerfile_spec.rb:10 # File "/entrypoint.sh" is expected to exist Fix the test entrypoint.sh #!/bin/sh Dockerfile
...Copy the file to a new location that is not tracked by Git Run RSpec example by description Run RSpec example by nesting index
...are during run-time, it's definitely possible. It's a lot easier in RSpec 2+. For example, consider this global before block where you'd want to run some...
...code for specific specs only: config.before do # stuff that_fancy_method # more stuff end RSpec 2+ If you want to run such a block for a specific type of specs...
Slow test suites are a major pain point in projects, often due to RSpec and FactoryBot. Although minitest and fixtures are sometimes viewed as outdated, they can greatly improve test...
...why is this setup faster? Partially, it's because minitest is more lightweight than RSpec, which as a testing DSL relies on Ruby's metaprogramming. The main speed boost, however...
...of the coverage into every executed spec: require 'testsort' coverage_measurement = Testsort::CoverageMeasurement.new coverage_measurement.start RSpec.configure do |config| config.after do |example| coverage_measurement.cover(example) end config.after(:suite) do coverage_measurement.finish end end
...and the saved coverage data, prioritize the specs by that and pass them to rspec to run in that order. Optional: You can also use the --strategy parameter to choose...
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...
...in your E2E tests, and you won't need avatars for all of them: RSpec RSpec has a helper method file_fixture: describe User do let(:user) { build(:user, attachment...
...file_fixture('avatar.jpg').open) } end You can configure the directory where RSpec looks for fixture files: RSpec.configure do |config| config.file_fixture_path = "spec/custom_directory" end Alternatives: Rails.root.join('spec/fixtures/files/avatar.jpg').open('r') Rails.root.join...
.../public/assets/', '/public/assets-test/', '/tmp/', ], 2. Report all existing offenses and exclude them initially Add an RSpec test, which runs ESLint (also during a full RSpec test run), e.g. in spec/eslint_spec.rb:
RSpec.describe 'eslint' do it 'is not offended' do stdout, stderr, status = Open3.capture3('yarn', 'run', 'eslint', '.') failure_message = [stderr, stdout].reject(&:empty?).join("\n\n") expect(status.success?).to eq(true...
...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