home.social

#rspec — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #rspec, aggregated by home.social.

fetched live
  1. 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:
    rubystacknews.com/2026/08/03/r

    #Ruby #Rails #RSpec

  2. 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:
    rubystacknews.com/2026/08/03/r

    #Ruby #Rails #RSpec

  3. Shared via my newsletter today: early access/WIP discount code for my new Rails TDD book: leanpub.com/everydayrails-test 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 leanpub.com/everydayrails-test to buy it for $9. Good forever! #Rspec

  4. Shared via my newsletter today: early access/WIP discount code for my new Rails TDD book: leanpub.com/everydayrails-test 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 leanpub.com/everydayrails-test to buy it for $9. Good forever! #Rspec

  5. I've written versions of an RSpec helper several times for modifying ENV in specs. Here's one:

    gist.github.com/soulcutter/b54

    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

    #ruby #rspec

  6. I've written versions of an RSpec helper several times for modifying ENV in specs. Here's one:

    gist.github.com/soulcutter/b54

    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

    #ruby #rspec

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

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

  9. After years of writing #rspec, I've been writing #minitest for the last year. One thing I missed, specially when writing Rails 'integration' tests was context/describe to group tests for an endpoint. It is not necessary at first, but as the _test.rb file grows I missed it more and more.

    #Ruby

  10. After years of writing #rspec, I've been writing #minitest for the last year. One thing I missed, specially when writing Rails 'integration' tests was context/describe to group tests for an endpoint. It is not necessary at first, but as the _test.rb file grows I missed it more and more.

    #Ruby

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

    go.fastruby.io/z30

    #RailsTesting #Accessibility #WCAG #RSpec #a11y

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

    go.fastruby.io/z30

    #RailsTesting #Accessibility #WCAG #RSpec #a11y

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

    #RubyOnRails #RSpec

    leanpub.com/everydayrailsrspec

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

    #RubyOnRails #RSpec

    leanpub.com/everydayrailsrspec

  15. #CoPilot obviously doesn't know how to do a proper test setup using #RSpec's context blocks in a "given-when-then" style. It hurts to read this stuff.

    #AI #ruby

  16. #CoPilot obviously doesn't know how to do a proper test setup using #RSpec's context blocks in a "given-when-then" style. It hurts to read this stuff.

    #AI #ruby

  17. ⚡ 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 🇯🇵

    🔗 rubystacknews.com/2026/02/18/%

    #Ruby #Rails #CI #RSpec #DevOps #Performance #KaigiOnRails

  18. ⚡ 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 🇯🇵

    🔗 rubystacknews.com/2026/02/18/%

    #Ruby #Rails #CI #RSpec #DevOps #Performance #KaigiOnRails

  19. Hi #ruby community I'm looking for other recommendation here codeberg.org/codeDude/romodoro

    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?

    #rails #coding #programming #unitTest #softwareDevelopment

  20. Hi #ruby community I'm looking for other recommendation here codeberg.org/codeDude/romodoro

    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?

    #rails #coding #programming #unitTest #softwareDevelopment

  21. @kerrick And #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.

  22. @kerrick And #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.

  23. Hello #ruby people, How can I test using #Rspec that accept method is receive(triggered). The class is here codeberg.org/codeDude/romodoro
    I having issues trying to mock and stub the dependencies

  24. Hello #ruby people, How can I test using #Rspec that accept method is receive(triggered). The class is here codeberg.org/codeDude/romodoro
    I having issues trying to mock and stub the dependencies

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

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

    #haskell #ruby #hspec #rspec

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

    #haskell #ruby #hspec #rspec

  28. 🥳 Happy 30th birthday to #RubyLang, still my favorite programming language! Here's a coupon for my #RSpec book for just $9, with practice #TDD advice. Free updates for Rails 8.1 and Ruby 4 coming early next year! Boosts appreciated! 🥳

    leanpub.com/everydayrailsrspec

  29. 🥳 Happy 30th birthday to #RubyLang, still my favorite programming language! Here's a coupon for my #RSpec book for just $9, with practice #TDD advice. Free updates for Rails 8.1 and Ruby 4 coming early next year! Boosts appreciated! 🥳

    leanpub.com/everydayrailsrspec

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

    andy-gallagher.com/blog/stop-v

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

    andy-gallagher.com/blog/stop-v

  32. TIL in #Ruby #RSpec,

    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!

  33. TIL in #Ruby #RSpec,

    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!

  34. @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]

  35. @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]

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

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

  38. @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 :(

    #rspec

  39. @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 :(

    #rspec

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

    #ruby

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

    #ruby

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

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

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

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

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

  47. (Specifically of debugging third-party packages causing deprecation warnings, praise be to #Rspec's `--backtrace` option and ` config.active_support.deprecation = :raise`)

  48. If your application has a `--color` flag, be like #Rspec, also support `--colour` as an alias, absolute praxis imo