Trending

#rspec

Latest posts tagged with #rspec on Bluesky

Latest Top
Trending

Posts tagged #rspec

Preview
Slashing API Response Times by 80%: Our Journey from 1.2s to 225ms How we eliminated N+1 queries, rebuilt our serialization layer, and achieved a 5x performance improvement that directly impacted our users.

At Lifen, we cut one of our highest-traffic Ruby on Rails API endpoints from 1.2s to 225ms response time 🎉

Here's a technical article I wrote about this process:
lifen.substack.com/p/slashing-a...

#Ruby #RSpec #Testing #Rails #OpenSource #TechWriting

1 0 0 0
Preview
GitHub - hoblin/claude-ruby-marketplace: Claude Code plugin marketplace for Ruby and Rails development Claude Code plugin marketplace for Ruby and Rails development - hoblin/claude-ruby-marketplace

Claude Code plugins for #Ruby / #Rails - LSP, #RSpec, #ActiveRecord, #MCP, Draper. PRs welcome.

github.com/hoblin/claude-ruby-marketplace

0 0 0 0
Preview
Everyday Rails Testing with RSpec Real-world advice for adding reliable tests to your Rails apps with RSpec. Learn to test with confidence!

🥳 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! 🥳

0 0 0 0
Blog post header image with white title "RSpec Tips & Tricks" and red subtitle "Rspec & testing using capybara" on black background. Features cute orange capybara mascot with question mark. Shows author Amanda Klusmeyer (Developer) with profile photo and Flagrant branding.

Blog post header image with white title "RSpec Tips & Tricks" and red subtitle "Rspec & testing using capybara" on black background. Features cute orange capybara mascot with question mark. Shows author Amanda Klusmeyer (Developer) with profile photo and Flagrant branding.

🧪 Amanda's RSpec debugging gems! CHROME=true for live test watching, save_and_open_screenshot for visual snapshots, save_and_open_page for HTML inspection. Essential for flaky spec debugging!
www.beflagrant.com/blog/rsp...
#RSpec #RubyOnRails #Testing

3 1 0 0

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!

1 0 1 0

2 months since I shared my first gem 🥳
I thought it might be time to repost myself for the occasion.

#Ruby #RSpec #Testing #Rails #OpenSource #TechWriting

1 0 0 0
Preview
Testing with RSpec book updates for September 2025 | Everyday Rails New content on top-down testing and covering your app's supporting features.

Hey #RubyFriends (and other friends too) 👋 I shipped a big change to my #RSpec book yesterday; here's a post about what's new and what's next. I appreciate your support!

1 0 0 0
What I'm up to (September 2025) | Aaron Sumner

I shared this the other day and mentioned how close I am on wrapping the current iteration of my #RSpec book. After a very productive flight, I'm happy to say the book is code complete! Now writing some remaining English words to explain my thinking, then on to your reader of choice. 😁

0 0 1 0
Preview
Everyday Rails Testing with RSpec Real-world advice for adding reliable tests to your Rails apps with RSpec. Learn to test with confidence!

Hey #RubyFriends, I haven't talked much #Ruby this summer. Life's been full, and I don't write much in my favorite language at my day job right now. But I am very close to (finally!) wrapping up the current edition of my #RSpec book. One more chapter to go!

2 0 1 0
Preview
GitHub - galtzo-floss/timecop-rspec: Timecop::Rspec provides Timecop time-machines for RSpec that allow you to time-travel test examples, context/describes, and/or your entire test suite. Timecop::Rspec provides Timecop time-machines for RSpec that allow you to time-travel test examples, context/describes, and/or your entire test suite. - galtzo-floss/timecop-rspec

💎 Fresh from the gem mine - timecop-rspec
Provides actual time-machines for RSpec that allow you to time-travel test examples, context/describes, and/or your entire test suite. Find out what your test will behave like... tomorrow! #Ruby #FLOSS #RSpec
github.com/galtzo-floss...

1 0 0 1

pura magia con Rspec y Factorybot... y no me gusta la magia en el código

#ruby #rspec

1 0 0 0

Software developer friends: When you're learning from a book, do you find end-of-chapter independent exercises useful, or skip them? I'm struggling a bit with meaningful exercises as I wrap up this version of my #RubyOnRails #RSpec book. (Boosts appreciated!)

1 1 1 0
Preview
GitHub - LucasMontorio/rspec-time-guard: A Time Guard that allows you to set timeouts to your RSpec tests A Time Guard that allows you to set timeouts to your RSpec tests - LucasMontorio/rspec-time-guard

🧵 Just published my deep dive into building RspecTimeGuard - a gem that stops RSpec tests from hanging indefinitely!

🔗 Gem: github.com/LucasMontori...

#Ruby #RSpec #Testing #Rails #OpenSource #TechWriting

3 2 1 1
Post image

Looking for that satisfying ‘I made my bed today’ kind of feeling? Check Cody Brooks' blog post and learn how to use FactoryBot with Plain Ole Ruby Objects (PORO) for all the details. www.beflagrant.com/blog/usi...

#Testing #FactoryBot #RSpec #Ruby #PORO #Software #Development

3 0 0 0
Preview
Joy of Test Driven Development(TDD) using Rspec in Ruby ## Joy of Test Driven Development(TDD) using Rspec in Ruby ### Prerequisites I am assuming that Ruby is already installed in your system. In this example, we will be using Ruby v3.4.4 We will be using Money example for TDD. ### Setup 1. Create a new directory called Money. 2. Create `Gemfile` file inside the directory and add only one line: `https://rubygems.org`. 3. Run `bundle add rspec` to install Rspec gem. You will notice that `Gemfile` is modified and `Gemfile.lock` is created. 4. Create two new directories called `spec` and `lib` ### Very very short introduction on TDD and Red-Green-Refactor cycle Test Driven Development(TDD) is methodology in software engineering where tests are written first and enough code is added to make all the tests pass. The Red-Green-Refactor cycle is a core principle of Test-Driven Development (TDD). It involves writing a test that fails (Red), implementing the minimum code to make the test pass (Green), and then improving the code's design (Refactor), while ensuring all tests continue to pass. ### Adding our first test Create file called `money_spec.rb` in `spec` directory. Inside `money_spec.rb`, let's type in our first test: require './lib/money.rb' describe Money do context '#initialize' do it { expect(Money.new(10, "USD")).to be_a(Money) } end end Now, type the command: `rspec spec/money_spec.rb` Check what's the error we are getting? An error occurred while loading ./spec/money_spec.rb. Failure/Error: require './lib/money.rb' LoadError: cannot load such file -- ./lib/money.rb # ./spec/money_spec.rb:1:in '<top (required)>' No examples found. Let's try to fix this issue and let's add a file called `money.rb` inside `lib` directory. Now, let's try running the command `rspec spec/money_spec.rb` command again. We will get yet, one more error. An error occurred while loading ./spec/money_spec.rb. Failure/Error: describe Money do context '#initialize' do it { expect(Money.new(10, "USD")).to be_a(Money) } end end NameError: uninitialized constant Money # ./spec/money_spec.rb:3:in '<top (required)>' No examples found. Let's try to fix this error by typing following lines of code: class Money end Now, we run the test again, we will get the following error: Failures: 1) Money#initialize Failure/Error: it { expect(Money.new(10, "USD")).to be_a(Money) } ArgumentError: wrong number of arguments (given 2, expected 0) # ./spec/money_spec.rb:5:in 'BasicObject#initialize' # ./spec/money_spec.rb:5:in 'Class#new' # ./spec/money_spec.rb:5:in 'block (3 levels) in <top (required)>' Finished in 0.00216 seconds (files took 0.05146 seconds to load) 1 example, 1 failure Failed examples: rspec ./spec/money_spec.rb:5 # Money#initialize In order to fix it, let's add following line of code: class Money attr_reader :amount def initialize(amount) @amount = amount end end Finally, you can see our first test case is passed. money rspec spec/money_spec.rb . Finished in 0.00243 seconds (files took 0.0397 seconds to load) 1 example, 0 failures Adding more tests - Red phase Now let's add more tests to our Money class. We want to test that our Money object can store amount and currency correctly. Let's update our money_spec.rb: require './lib/money.rb' describe Money do context '#initialize' do it { expect(Money.new(10, "USD")).to be_a(Money) } it 'stores the amount correctly' do money = Money.new(25, "USD") expect(money.amount).to eq(25) end it 'stores the currency correctly' do money = Money.new(25, "USD") expect(money.currency).to eq("USD") end end end Run the tests: rspec spec/money_spec.rb ... Finished in 0.00312 seconds (files took 0.04221 seconds to load) 3 examples, 0 failures Great! All tests are passing. Now let's add functionality to compare two Money objects. Testing equality - Red phase Let's add a test for equality comparison: require './lib/money.rb' describe Money do context '#initialize' do it { expect(Money.new(10, "USD")).to be_a(Money) } it 'stores the amount correctly' do money = Money.new(25, "USD") expect(money.amount).to eq(25) end it 'stores the currency correctly' do money = Money.new(25, "USD") expect(money.currency).to eq("USD") end end context '#==' do it 'returns true when amount and currency are the same' do money1 = Money.new(10, "USD") money2 = Money.new(10, "USD") expect(money1 == money2).to be true end it 'returns false when amounts are different' do money1 = Money.new(10, "USD") money2 = Money.new(20, "USD") expect(money1 == money2).to be false end it 'returns false when currencies are different' do money1 = Money.new(10, "USD") money2 = Money.new(10, "EUR") expect(money1 == money2).to be false end end end When we run the test, we get: Failures: 1) Money#== returns true when amount and currency are the same Failure/Error: expect(money1 == money2).to be true expected: true got: false 2) Money#== returns false when amounts are different Failure/Error: expect(money1 == money2).to be false expected: false got: true 3) Money#== returns false when currencies are different Failure/Error: expect(money1 == money2).to be false expected: false got: true Finished in 0.00421 seconds (files took 0.04532 seconds to load) 6 examples, 3 failures Making equality tests pass - Green phase Let's implement the == method in our Money class: class Money attr_reader :amount, :currency def initialize(amount, currency) @amount = amount @currency = currency end def ==(other) return false unless other.is_a?(Money) amount == other.amount && currency == other.currency end end Now when we run the tests: rspec spec/money_spec.rb ...... Finished in 0.00387 seconds (files took 0.04123 seconds to load) 6 examples, 0 failures Excellent! All tests are passing. Adding arithmetic operations - Red phase Let's add tests for adding two Money objects: require './lib/money.rb' describe Money do context '#initialize' do it { expect(Money.new(10, "USD")).to be_a(Money) } it 'stores the amount correctly' do money = Money.new(25, "USD") expect(money.amount).to eq(25) end it 'stores the currency correctly' do money = Money.new(25, "USD") expect(money.currency).to eq("USD") end end context '#==' do it 'returns true when amount and currency are the same' do money1 = Money.new(10, "USD") money2 = Money.new(10, "USD") expect(money1 == money2).to be true end it 'returns false when amounts are different' do money1 = Money.new(10, "USD") money2 = Money.new(20, "USD") expect(money1 == money2).to be false end it 'returns false when currencies are different' do money1 = Money.new(10, "USD") money2 = Money.new(10, "EUR") expect(money1 == money2).to be false end end context '#+' do it 'adds two Money objects with same currency' do money1 = Money.new(10, "USD") money2 = Money.new(20, "USD") result = money1 + money2 expect(result).to eq(Money.new(30, "USD")) end it 'raises error when currencies are different' do money1 = Money.new(10, "USD") money2 = Money.new(20, "EUR") expect { money1 + money2 }.to raise_error(ArgumentError, "Cannot add different currencies") end end end Running the tests: Failures: 1) Money#+ adds two Money objects with same currency Failure/Error: result = money1 + money2 NoMethodError: undefined method `+' for #<Money:0x000001234567890> 2) Money#+ raises error when currencies are different Failure/Error: expect { money1 + money2 }.to raise_error(ArgumentError, "Cannot add different currencies") NoMethodError: undefined method `+' for #<Money:0x000001234567890> Finished in 0.00456 seconds (files took 0.04234 seconds to load) 8 examples, 2 failures Implementing addition - Green phase Let's implement the + method: class Money attr_reader :amount, :currency def initialize(amount, currency) @amount = amount @currency = currency end def ==(other) return false unless other.is_a?(Money) amount == other.amount && currency == other.currency end def +(other) raise ArgumentError, "Cannot add different currencies" unless currency == other.currency Money.new(amount + other.amount, currency) end end Running the tests: rspec spec/money_spec.rb ........ Finished in 0.00445 seconds (files took 0.04567 seconds to load) 8 examples, 0 failures Perfect! All tests are passing. Adding subtraction - Red, Green cycle Let's add subtraction functionality: # Add to money_spec.rb in the context '#+' section context '#-' do it 'subtracts two Money objects with same currency' do money1 = Money.new(30, "USD") money2 = Money.new(10, "USD") result = money1 - money2 expect(result).to eq(Money.new(20, "USD")) end it 'raises error when currencies are different' do money1 = Money.new(30, "USD") money2 = Money.new(10, "EUR") expect { money1 - money2 }.to raise_error(ArgumentError, "Cannot subtract different currencies") end end Add the implementation: class Money attr_reader :amount, :currency def initialize(amount, currency) @amount = amount @currency = currency end def ==(other) return false unless other.is_a?(Money) amount == other.amount && currency == other.currency end def +(other) raise ArgumentError, "Cannot add different currencies" unless currency == other.currency Money.new(amount + other.amount, currency) end def -(other) raise ArgumentError, "Cannot subtract different currencies" unless currency == other.currency Money.new(amount - other.amount, currency) end end Adding string representation - Red, Green cycle Let's add a test for string representation: context '#to_s' do it 'returns string representation of money' do money = Money.new(25, "USD") expect(money.to_s).to eq("$25.00 USD") end it 'handles different currencies' do money = Money.new(50, "EUR") expect(money.to_s).to eq("€50.00 EUR") end end Implementation: rubyclass Money attr_reader :amount, :currency def initialize(amount, currency) @amount = amount @currency = currency end def ==(other) return false unless other.is_a?(Money) amount == other.amount && currency == other.currency end def +(other) raise ArgumentError, "Cannot add different currencies" unless currency == other.currency Money.new(amount + other.amount, currency) end def -(other) raise ArgumentError, "Cannot subtract different currencies" unless currency == other.currency Money.new(amount - other.amount, currency) end def to_s symbol = currency_symbol(currency) "#{symbol}#{'%.2f' % amount} #{currency}" end private def currency_symbol(currency) case currency when "USD" "$" when "EUR" "€" when "GBP" "£" else "" end end end Final test run Let's run all our tests to make sure everything works: rspec spec/money_spec.rb ............ Finished in 0.00623 seconds (files took 0.04891 seconds to load) 12 examples, 0 failures Refactor phase Now that all our tests are passing, let's refactor our code to make it cleaner. We can extract the currency validation into a private method: class Money attr_reader :amount, :currency def initialize(amount, currency) @amount = amount @currency = currency end def ==(other) return false unless other.is_a?(Money) amount == other.amount && currency == other.currency end def +(other) validate_same_currency(other) Money.new(amount + other.amount, currency) end def -(other) validate_same_currency(other) Money.new(amount - other.amount, currency) end def to_s symbol = currency_symbol(currency) "#{symbol}#{'%.2f' % amount} #{currency}" end private def validate_same_currency(other) unless currency == other.currency raise ArgumentError, "Cannot perform operation on different currencies" end end def currency_symbol(currency) case currency when "USD" "$" when "EUR" "€" when "GBP" "£" else "" end end end Run the tests one final time: rspec spec/money_spec.rb ............ Finished in 0.00589 seconds (files took 0.04723 seconds to load) 12 examples, 0 failures ### Conclusion Through this example, we've demonstrated the Red-Green-Refactor cycle of TDD using RSpec in Ruby. We started with simple tests, made them pass with minimal code, and then refactored to improve the design. This approach ensures that our code is well-tested, reliable, and maintainable. The key benefits of TDD that we experienced: Writing tests first helps clarify requirements Small, incremental steps make debugging easier Refactoring with confidence knowing tests will catch regressions Better code design through thinking about usage first TDD takes practice, but once you get comfortable with the rhythm, you'll find it leads to better, more reliable code.
0 0 0 0

Hey friends! Just a reminder that this sale is going on all month. ❤️ to all your support these past 15 years. (And if $9 is out of your budget, DM me for a freebie link, no questions asked) #RSpec #RubyOnRails #RubyFriends #IndiePublisher

1 0 0 0

Anyone have better approaches to wiping Active Storage files after #RSpec test runs in #RubyOnRails?

```
config.after(:suite) do
dir = ActiveStorage::Blob.services.fetch(:test).root
FileUtils.rm_rf(dir)
FileUtils.mkdir_p(dir)
FileUtils.touch(File.join(dir, ".keep"))
end
```

5 1 1 0
Preview
Everyday Rails Testing with RSpec Real-world advice for adding reliable tests to your Rails apps with RSpec. Learn to test with confidence!

Welp, my improptu 15th anniversary sale became a "just needed to buy a new washer/dryer" sale 😭 $9 for lifetime free updates to my #RubyOnRails #RSpec book! Sharing is caring!

0 0 0 1
Original post on mastodon.social

The output of RSpec's "expect(thing).to recieve(:act).with('foo')" can be a pain to debug if "act" is called with things other than "foo". But TIL combining "expect" with "allow" lists the calls:

class Dog
def say(sound); end
end

it "says bark" do
dog = Dog.new
allow(dog).to receive(:say) […]

0 0 0 0
Post image

#ForSale: 2020 #Yamaha #Bolt #RSpec - #Motorcycles - #AustinTX at #Geebo

austin-tx.geebo.com/vehicles/vie...

0 0 0 0
Preview
GitHub - MoskitoHero/zed-test-toggle: A small gem to toggle between source and test in the Zed editor A small gem to toggle between source and test in the Zed editor - MoskitoHero/zed-test-toggle

Made a small gem to allow switching from class to test - and back - in #zed

github.com/MoskitoHero/...

It’s still at an early stage, so I suspect it might not work in some projects. But it understands if you are using #rspec or #minitest.

#ruby #gem

8 3 1 0
Preview
Everyday Rails Testing with RSpec Real-world advice for adding reliable tests to your Rails apps with RSpec. Learn to test with confidence!

💥 I shipped a new chapter for the current edition of Everyday Rails Testing with #RSpec! I’ve overhauled my introduction to testing in isolation with mocks (and stubs, and fakes, and spies, and doubles, oh my). 💥

Free update on Leanpub: https://leanpub.com/everydayrailsrspec/

#RubyOnRails

0 0 1 1

#RubyOnRails pals—I'm not super in-the-loop at the moment, but is there a ballpark on when Rails 8.1 is going to drop? For context, I'm thinking about pausing on content updates on my #RSpec book, do a quick 8.0 update for the chapters done so far, then wrap up the remaining chapters.

0 0 2 0

Updating coverage of the Ruby "VCR" mocking package in my #RSpec book, and thinking how many younger people have likely never even seen a VCR, much less a TiVo—which then reminded me of the behemoth ReplayTV that sat under my cathode ray television in the aughts. 👴

0 0 0 0
Preview
Everyday Rails Testing with RSpec Real-world advice for adding reliable tests to your Rails apps with RSpec. Learn to test with confidence!

Finally got an update to my #RSpec book for #RubyOnRails shipped this afternoon, with new content on tools for DRYer tests, and when they're a good idea or a bad idea. Free update as usual!

4 2 1 0
Specs at a Single Level of Abstraction Every intro to testing tutorial out there will have you write tests at multiple levels of abstraction. With larger test suites, this can get quite unwieldy as your readers are forced to abstract on the fly. As Ruby devs, it’s our mission to increase readibility and conciseness at every turn.

Heya #TDD fans, especially #RSpec users: Feelings about testing at a single level of abstraction? Debating whether to include it again (with revisions) in my RSpec book updates. I like it in principle; is the extra setup worth the improved readability to you?

0 0 0 1

So I was looking for #rspec integration of difftastic and there was none, so I made one. After playing a bit on a private repo, I pushed to GitHub and upon trying to publish the gem, the name was taken. So someone pushed one 2 days ago 🤷‍♂️ Anyway, now I’ll contribute, as I did a bit deeper integration

0 0 0 0
A prompt from Cursor AI editor asking it to write a script that will find combinations for all test scenarios from one file and run them along with another file to find the combination that causes failure in that other file

A prompt from Cursor AI editor asking it to write a script that will find combinations for all test scenarios from one file and run them along with another file to find the combination that causes failure in that other file

Terminal showing output from running the script that found the offending scenario

Terminal showing output from running the script that found the offending scenario

One more prompt and we found the culprit 🙃 Now I just asked it to find which specific spec scenario causes our failure and 💥 got it, fixed it, and now I also know that there's state leaking between specs which I want to address in a generic way. Win!

#aicoding #testing #rspec #debugging #ruby

0 0 0 0
Preview
11- On tests and RSpec A Junior, A Senior and I · Episode

🎙️New Episode Alert!🎙️

Steven and Philippe joined me to dive deep into testing and RSpec. We covered best practices, common pitfalls, and shared some real-world insights that every developer can relate to.

Listen here: open.spotify.com/episode/08C0...

#Podcast #RSpec #Testing #TechTalk #Ruby

0 0 1 0
Original post on ruby.social

Because I CAN'T just go by the book, I am making work for myself that no one asked me to do... because learning. So I am working through Effective Testing with #RSpec 3 with the @wnb_rb bookclub, but it uses #sinatra which is a perfectly nice, very easy to use framework. And I just wanted to […]

1 0 1 0