When a spec only runs when it is called directly, but not as part of the whole test suite, make...

github.com

A comprehensive script to convert test suites from RSpec 2 to RSpec 3. This converts more than should/expect syntax...

blog.bitcrowd.net

To make the RSpec matcher of the authorization solution Consul work with Rspec 2.x read the following blog post...

relishapp.com

...and_call_original object.should_receive(:some_method).with('my argument').and_return('other value') Requires rspec-mocks...

...arrays have the same elements regardless of order, you can use the =~ matcher in RSpec < 2.11: actual_array.should =~ expected_array If either side is an ActiveRecord scope rather than an array...

...first, since =~ does not play nice with scopes: actual_scope.to_a.should =~ expected_scope.to_a If you use RSpec >= 2.11 we recommend using the match_array or contain_exactly matchers instead of =~.

rspec.info

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...

makandra Curriculum

...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...

...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...

...You probably want to enable CSRF protection in tests that can speak JavaScript. For RSpec feature tests Add this to any file to the spec/support folder: RSpec.configure do |config| config.around...

ActionController::Base.config.allow_forgery_protection = original end end Also make sure you have configured RSpec to load all files in spec/support. For Cucumber tests Add this to any file in...

tekin.co.uk

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...

...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...

...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...

makandra dev

...use the following GitHub Actions template for the CI integration. It includes jobs for rspec (parallelized using knapsack, unit + feature specs), rubocop, eslint, coverage and license_finder. Note that GitHub...

...name: Precompile assets run: bundle exec rails assets:precompile - name: Run parallel tests id: rspec run: | CI_NODE_TOTAL=4 CI_NODE_INDEX=${{ matrix.partition }} \ bundle exec rails "knapsack:rspec"

...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...

makandracards.com

...Copy the file to a new location that is not tracked by Git Run RSpec example by description Run RSpec example by nesting index

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

...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 pending...

makandra dev

.../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...