RSpec example groups can be named using symbols
Though nowhere to be found in the official docs, this works just fine.
describe Facebook::Post do
it_behaves_like :time_series
end
shared_examples_for :time_series do
# shared example code
end
Related cards:
Cancelling the ActiveRecord callback chain
What | Rails version | Within before_*
|
Within after_*
|
---|---|---|---|
Cancel later callbacks | Rails 1-4 | `re... |
Testing shared traits or modules without repeating yourself
When two classes implement the same behavior (methods, callbacks, etc.), you should extract that behavior into a trait or module. This card describes how to test that extracted behavior without repeating y...
RSpec: Tagging examples and example groups
In RSpec you can tag examples or example groups with any tags you like simply by saying
describe ReportCreator, slow: true do
# ..
end
describe ReportCreator do
it 'generates reports', slow: true do
# ...
end
end
You can ...
RSpec: run a single spec (Example or ExampleGroup)
RSpec allows you to mark a single Example/ExampleGroup so that only this will be run. This is very useful when using a test runner like guard.
Add the following config to spec/spec_helper.rb
:
RSpec.configure do |config|
# These two s...
Running Rspec examples by name, or: Running a single shared example
When an Rspec example fails, I usually investigate by running that example again using rspec <file:line>
. However, this does not work with shared examples, since Rspec doesn't know in which context the shared example should be run.
But there is...
Ruby: Using named groups in Regex
An alternative of using a multiple assignment for a Regex are named groups. Especially when your Regex becomes more complicates it is easier...
The JavaScript Object Model: A deep dive into prototypes and properties
Speaker today is Henning Koch, Head of Development at makandra.
This talk will be in German with English slides.
Introduction
As web developers we work with JavaScript every day, even when our backend code uses anothe...
RSpec < 2.11: ActiveRecord scopes must be loaded before using the "=~" matcher
To test whether two 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, you should ca...
Associations named using a string cannot be included in a scope
If you defined your association via
class Article
belongs_to "category"
end
and you try
Article.scoped(:include => :category)
you will get an error message
in `preload_one_association': Association named 'cat...
How to fix: WrongScopeError when using rspec_rails with Rails 6.1
tl;dr: Upgrade the gem to at least 4.0.1
When you use rspec_rails
in a version < 4 with Rails 6.1 you may encounter an error like this:
Failure/Error:
raise WrongScopeError,
"`#{name}` is not available from within an example (e.g. an ...