#rspec — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #rspec, aggregated by home.social.
-
Most Ruby developers use only a fraction of what RSpec Expectations can do.
eq, be, eql, contain_exactly, raise_error, compound matchers...
Are you choosing the right matcher for the behavior you're testing?Read more:
https://rubystacknews.com/2026/08/03/rspec-expectations-youre-probably-using-the-wrong-matcher/ -
Most Ruby developers use only a fraction of what RSpec Expectations can do.
eq, be, eql, contain_exactly, raise_error, compound matchers...
Are you choosing the right matcher for the behavior you're testing?Read more:
https://rubystacknews.com/2026/08/03/rspec-expectations-youre-probably-using-the-wrong-matcher/ -
Shared via my newsletter today: early access/WIP discount code for my new Rails TDD book: https://leanpub.com/everydayrails-testing-from-scratch/c/CDD5705EB0DE Just $9 until I'm done with this release (early September-ish). #Rails #TDD #IndiePublishing
Anyone who bought my RSpec book through Leanpub, ever, can use https://leanpub.com/everydayrails-testing-from-scratch/c/supporters to buy it for $9. Good forever! #Rspec
-
Shared via my newsletter today: early access/WIP discount code for my new Rails TDD book: https://leanpub.com/everydayrails-testing-from-scratch/c/CDD5705EB0DE Just $9 until I'm done with this release (early September-ish). #Rails #TDD #IndiePublishing
Anyone who bought my RSpec book through Leanpub, ever, can use https://leanpub.com/everydayrails-testing-from-scratch/c/supporters to buy it for $9. Good forever! #Rspec
-
I've written versions of an RSpec helper several times for modifying ENV in specs. Here's one:
https://gist.github.com/soulcutter/b54e6e83c0a9a0dca1ff1ff9ffde2a4e
I shy away from the climate_control gem because a whole 'nother dependency for this seems meh - but go ahead and poke holes in my opinion/implementation
-
I've written versions of an RSpec helper several times for modifying ENV in specs. Here's one:
https://gist.github.com/soulcutter/b54e6e83c0a9a0dca1ff1ff9ffde2a4e
I shy away from the climate_control gem because a whole 'nother dependency for this seems meh - but go ahead and poke holes in my opinion/implementation
-
Finally today I researched alternatives (that don't involve enabling the #rspec DSL, as I'm interesting in the minitest-way) and using nested classes to group tests is a solution I landed on. One thing that I like about the solution is that it 'plain' Ruby. My appreciation for #minitest is grows the more I use it, as it teaches/forces you to learn into 'plain' #Ruby.
Note: I'm using 'plain' as opposed to DSL/meta-programming. In that simple OO vs DSL heavy are the two wolves of #Ruby
-
Finally today I researched alternatives (that don't involve enabling the #rspec DSL, as I'm interesting in the minitest-way) and using nested classes to group tests is a solution I landed on. One thing that I like about the solution is that it 'plain' Ruby. My appreciation for #minitest is grows the more I use it, as it teaches/forces you to learn into 'plain' #Ruby.
Note: I'm using 'plain' as opposed to DSL/meta-programming. In that simple OO vs DSL heavy are the two wolves of #Ruby
-
Accessibility does not have to be a manual audit you dread...
Drop `axe-core-rspec` and `axe-core-capybara` into your Rails test suite and the `be_axe_clean` matcher catches color contrast failures and missing alt text right in your specs.
WCAG boils down to four ideas: perceivable, operable, understandable, robust. Test for them and you ship apps usable by everyone, not just most people.
-
Accessibility does not have to be a manual audit you dread...
Drop `axe-core-rspec` and `axe-core-capybara` into your Rails test suite and the `be_axe_clean` matcher catches color contrast failures and missing alt text right in your specs.
WCAG boils down to four ideas: perceivable, operable, understandable, robust. Test for them and you ship apps usable by everyone, not just most people.
-
ICYMI, I updated my RSpec testing book for Rails 8.1 and Ruby 4.0! Learn to test—and think about tests—the way I did, through a hands-on, full-stack approach. Minimal theory and dogma—just a straightforward, practical, and time-tested guide to software testing
I'm running a launch discount through April for $9 (regularly $19), and as always, it's a free update if you got your copy through Leanpub.
Please pass along; sharing is caring 🤗
-
ICYMI, I updated my RSpec testing book for Rails 8.1 and Ruby 4.0! Learn to test—and think about tests—the way I did, through a hands-on, full-stack approach. Minimal theory and dogma—just a straightforward, practical, and time-tested guide to software testing
I'm running a launch discount through April for $9 (regularly $19), and as always, it's a free update if you got your copy through Leanpub.
Please pass along; sharing is caring 🤗
-
【Rails】RSpecの導入からモデルテストを書き方まで|FactoryBot・Fakerでハマったポイントまとめ
https://qiita.com/masa_tech_0326/items/b5f51a60674113a91158?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items -
This is an interesting article about parallel testing and CI https://visuality.pl/posts/parallel_tests_without_waiting
-
This is an interesting article about parallel testing and CI https://visuality.pl/posts/parallel_tests_without_waiting
-
⚡ From ~30 minutes to ~2 minutes: how a Rails team achieved ultra-fast CI — without rewriting tests.
Parallel RSpec done right, smart workload balancing, PostgreSQL on tmpfs (RAM), and even reconsidering cloud vs physical hardware.
Inspired by a Kaigi on Rails 2025 talk 🇯🇵
-
⚡ From ~30 minutes to ~2 minutes: how a Rails team achieved ultra-fast CI — without rewriting tests.
Parallel RSpec done right, smart workload balancing, PostgreSQL on tmpfs (RAM), and even reconsidering cloud vs physical hardware.
Inspired by a Kaigi on Rails 2025 talk 🇯🇵
-
Hi #ruby community I'm looking for other recommendation here https://codeberg.org/codeDude/romodoro-socket/src/branch/main/lib/romodoro/socket/timer/countdown.rb
I''m not sure how to test this with #Rspec
basically the intention is test if the duration is for example 2 seconds the countdown spend 2 seconds.
Could you gimme ideas please?
-
Hi #ruby community I'm looking for other recommendation here https://codeberg.org/codeDude/romodoro-socket/src/branch/main/lib/romodoro/socket/timer/countdown.rb
I''m not sure how to test this with #Rspec
basically the intention is test if the duration is for example 2 seconds the countdown spend 2 seconds.
Could you gimme ideas please?
-
Whenever I have to use anything other than #Ruby, I am immediately reminded of how every single testing framework is miles, no, light-years behind RSpec.
-
Whenever I have to use anything other than #Ruby, I am immediately reminded of how every single testing framework is miles, no, light-years behind RSpec.
-
Hello #ruby people, How can I test using #Rspec that accept method is receive(triggered). The class is here https://codeberg.org/codeDude/romodoro-socket/src/branch/main/lib/romodoro/socket/timer/command_server.rb#L24
I having issues trying to mock and stub the dependencies -
Hello #ruby people, How can I test using #Rspec that accept method is receive(triggered). The class is here https://codeberg.org/codeDude/romodoro-socket/src/branch/main/lib/romodoro/socket/timer/command_server.rb#L24
I having issues trying to mock and stub the dependencies -
As expected, the ~65% #RSpec test coverage meant that there have been several issues which came up during manual testing, including some very pleasantly head-scratching ones 🧠
-
SecureRandom を stub すると、なぜ Rails の CSRF が壊れるのか
https://qiita.com/okarina-chaan/items/747be079183dd0d6cc83?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items -
hspec uses the same syntax Rspec used many years ago.
Makes me feel nostalgic.
Had to write a spec for some Ruby code recently, turns out instead of function(args).should_equal result one now has to write expect(function(args).to == result.
Oh why?
-
hspec uses the same syntax Rspec used many years ago.
Makes me feel nostalgic.
Had to write a spec for some Ruby code recently, turns out instead of function(args).should_equal result one now has to write expect(function(args).to == result.
Oh why?
-
Nice article about structuring your tests #ruby #rspec https://thoughtbot.com/blog/the-arrange-act-assert-pattern
-
Nice article about structuring your tests #ruby #rspec https://thoughtbot.com/blog/the-arrange-act-assert-pattern
-
This. I've seen a lot of garbage tests this year. I like #RSpec's `xit` shorthand for walking more slowly and deliberately through test scenarios, regardless of whether an agent is involved or not.
https://www.andy-gallagher.com/blog/stop-vibe-coding-your-unit-tests/
-
This. I've seen a lot of garbage tests this year. I like #RSpec's `xit` shorthand for walking more slowly and deliberately through test scenarios, regardless of whether an agent is involved or not.
https://www.andy-gallagher.com/blog/stop-vibe-coding-your-unit-tests/
-
this:
expect(File.exist?(old_file)).to be true
can be shortened to this:
expect(File).to exist(old_file)
expect(File).to exist old_file
Neat!
-
this:
expect(File.exist?(old_file)).to be true
can be shortened to this:
expect(File).to exist(old_file)
expect(File).to exist old_file
Neat!
-
@postmodern and also, why doesn't #Ruby itself have an opposite direction of .include? method?
[1, 2, 3].include? 1
Like #Rails’ .in?
1.in? [1, 2, 3]
Then the #RSpec would be:
expect(1).to be_in [1, 2, 3]
-
@postmodern and also, why doesn't #Ruby itself have an opposite direction of .include? method?
[1, 2, 3].include? 1
Like #Rails’ .in?
1.in? [1, 2, 3]
Then the #RSpec would be:
expect(1).to be_in [1, 2, 3]
-
continuing about collection-based #rspec matchers...
When using `match` and `include` you can let the `it` spec to speak for itself:
```ruby
context 'when one of the values is off' do
it do
expect(subject).to match(
error: 'P',
context: be_a(String).and( eq('S'))
)
end
end
```I tend to not declare what the `it` is, because it's gratifying see its errors :), usually that's the context blocks are for.
* puns intended
# ruby -
continuing about collection-based #rspec matchers...
When using `match` and `include` you can let the `it` spec to speak for itself:
```ruby
context 'when one of the values is off' do
it do
expect(subject).to match(
error: 'P',
context: be_a(String).and( eq('S'))
)
end
end
```I tend to not declare what the `it` is, because it's gratifying see its errors :), usually that's the context blocks are for.
* puns intended
# ruby -
@benjamineskola I'd argue that relying on concrete type is something the spec shouldn't care, at least not in #ruby
For example, perhaps it started with a hash, and that was OK, but later on the team want to change the implementation to use something else, like a Struct class.
Error = Struct.new('ErrorStruct', :error, :context)
error = Error.new('Pusher error', 'oops!')
then `be_hash_including` might fail because it's not a hash, is an Struct. Image having 433 spec files :(
-
@benjamineskola I'd argue that relying on concrete type is something the spec shouldn't care, at least not in #ruby
For example, perhaps it started with a hash, and that was OK, but later on the team want to change the implementation to use something else, like a Struct class.
Error = Struct.new('ErrorStruct', :error, :context)
error = Error.new('Pusher error', 'oops!')
then `be_hash_including` might fail because it's not a hash, is an Struct. Image having 433 spec files :(
-
Lately I've found some resistance to use collection-based #rspec matchers
Checking element by element is technically not wrong:
expect(failure[:error]).to eq('Pusher error')
expect(failure[:context]).to eq('notify_notification_started')but using `match` & `include` has their advantages:
expect(failure).to match(
error: 'Pusher error'
context: 'notify_notification_started'
)I can elaborate further if someone ask for it.
Perhaps a blog post about it is needed?
-
Lately I've found some resistance to use collection-based #rspec matchers
Checking element by element is technically not wrong:
expect(failure[:error]).to eq('Pusher error')
expect(failure[:context]).to eq('notify_notification_started')but using `match` & `include` has their advantages:
expect(failure).to match(
error: 'Pusher error'
context: 'notify_notification_started'
)I can elaborate further if someone ask for it.
Perhaps a blog post about it is needed?
-
## Please Don't Nerf RubyLang Because #StyleGuides
Ruby has made some internal changes that remind me of the changes #RSpec made to clean up internals but uglified the code & made certain features simply stop working as expected.
Removing `foo rescue nil` is an exmaple. Some edge cases make this antipattern useful; replacing a one-liner with a complex method/chain is annoying. Mindful chainsaw-juggling gave expert #Rubyists superpowers. Not trusting power users is red #Kryptonite for code.
-
## Please Don't Nerf RubyLang Because #StyleGuides
Ruby has made some internal changes that remind me of the changes #RSpec made to clean up internals but uglified the code & made certain features simply stop working as expected.
Removing `foo rescue nil` is an exmaple. Some edge cases make this antipattern useful; replacing a one-liner with a complex method/chain is annoying. Mindful chainsaw-juggling gave expert #Rubyists superpowers. Not trusting power users is red #Kryptonite for code.
-
One downside of setting myself the stretch goal of "adding #RSPec tests for all URL routes" is that there are a LOT of them 😅
(`rails routes` says 303)
This is of course making this task take forever (~15 hours' work to improve test coverage from ~40% to ~65%).
But, more also-importantly, it's ruining my "lines of code deleted" metric, I have added over 2000 lines of specs alone 🙈
-
I'm liking how the #RSpec tests are shaping up overall though.
I'd be really interested to get some review from someone with more experience; I did find a few examples of "request" specs (which is the main layer I've decided to start with) around, but there seem to be several different taste preferences going on.
So far, having a "context" for each combination of HTTP verb + endpoint is working out reasonably, and then separate blocks to test unauthenticated / unauthorised / success
-
#RSpec interactive debugging with #Neovim: I tried a lot, I failed a lot.
I got this working for other languages (#Python and #CSharp) and it was a HUGE help, taking away one of the main things I need to leave my editor for.
But something is blowing up and I'm still relatively new to Neotest, DAP, and the various plumbing between them and the test runners.
-
(Specifically of debugging third-party packages causing deprecation warnings, praise be to #Rspec's `--backtrace` option and ` config.active_support.deprecation = :raise`)
-
If your application has a `--color` flag, be like #Rspec, also support `--colour` as an alias, absolute praxis imo