Pro-tip for writing custom RSpec methods and trying to report the correct file and line number:
# WHY won't RSpec let me set the location!? (ノಠ益ಠ)ノ彡┻━┻
RSpec::Core::Metadata::RESERVED_KEYS.delete(:location)
Someone please tell me how I’m doing it wrong and that there’s actually a good idea in #RSpec somewhere to make your own spec methods.
A walk through of building fast #RSpec tests to iterate on a low-level #Ruby function. This post talks about the idea of using test tables to help provide examples of both given inputs and expected outputs. I also walk through a #refactoring.
Please reach out if you'd like to learn more or are curious about how me and my team might be able to help you meet your business needs.
This is very specific, but passing `-- headless=new` to #Chrome (Chromium, to be precise) v115 using #Capybara and #Selenium on #AlpineLinux running in #Docker is a recipe for pain.
Intermittent #RSpec system spec failures surfaced as anything from failed page navigations to obscure session errors. I _think_ the browser was crashing between spec setup and `visit`.
Removing `=new` and the intermittent failures appear to have ceased. “Solved” in an entirely unsatisfying manner. 🤦🏻♂️
#ruby #rspec #docker #alpinelinux #selenium #capybara #chrome
So I had a Patch Request fixing our CI at work because an error was persistently showing up, suddenly, out of the blue. No changes in the reported specs failing - they were introduced by me18 days ago.
Let's keep this between us. Don't tell anybody. It's a secret between you, me, my coworkers and the internet.
#meaculpa #ci #development #ruby #rspec
Sometimes I see #rspec tests with the classic "describe SomeClass do ..." beginning for a class-scoped test suite.
IIRC, Rspec will implicitly call SomeClass.new when a test references "subject" directly.
With that in mind, what's your favorite pattern to instantiate SomeClass with different keyword params in different tests? Do you still use subject for that?
I kinda want an `eventually` keyword in #RSpec so I can write `expect { foo }.eventually(wait: 5).to be_present?` which will re-evaluate the block and then make the assertion...
“É melhor ter teste ruim do que não ter testes.”
Já eu, penso o contrário. Acredito que é melhor *não* ter teste do que ter teste ruim. Se você não tem testes você é obrigado a testar de forma manual toda vez que alterar algo no seu código e isso, querendo ou não, pode trazer mais confiabilidade do que uma suíte frágil, repleta de falso positivo, mistery guest pra todo lado com mais lógica do que a que própria implementação.
⚡ Want to learn how to test AJAX controller requests with different versions of Rails and RSpec? Engineer Aysan Isayo wrote a full guide on how to: https://www.fastruby.io/blog/rails/rspec/testing-ajax-controller-requests.html?utm_source=Mastodon&utm_medium=Organic&utm_campaign=Blogpromo&utm_term=ajaxcontrollerrequest&utm_content=Graphic&utm_id=
#rspec #asynchronousjavascript #rubyonrails #railsupgrades #javascript
#rspec #asynchronousjavascript #rubyonrails #railsupgrades #javascript
Shout outs to the rspec-wait gem, makes testing a lot easier and more consistent!
@pauldruziak Regarding #Rspec for #Ruby developers, as long as your "expect" blocks test enough of the function of the class, I think it's good. An example of inadequate tests would be something like having tests that have no expect blocks and simply exist to make sure no exceptions are thrown, or tests that mock too much of the functionality and barely end up doing anything except guard against basic exceptions being thrown.
Check out my new blog post about #Pundit and different #RSpec test approaches.
https://tobiasmaier.info/posts/2023/06/19/pundit-rspec-approaches.html
#pundit #rspec #ruby #rubyonrails #authz #authorization
This makes me happy. I added more #rspec tests, but sped up the test suite with applying some best practices with new test, and cleanup some of the existing ones. It's nice to leave things better than you found them, especially legacy code bases 😁
Went from a full test suite run:
1 minute 4.93 seconds (files took 1.97 seconds to load)
96 examples, 0 failures
To:
58.19 seconds (files took 1.97 seconds to load)
112 examples, 0 failures
#CrystalLang comes with its own version of #RSpec built in. However, I can't seem to find a Crystal equivalent for #CucumberBDD, although I've heard anecdotally that Turnip (which embeds #GherkinSyntax into RSpec) works even if it lacks some of Cucumber's full feature set. What do Crystal programmers use as a drop-in replacement or alternative implementation for #RubyLang Cucumber?
#crystallang #rspec #cucumberbdd #gherkinsyntax #rubylang
When I write my pytests I ask myself, "how would I do this in rspec?"
#Python #sorrynotsorry #Ruby #rspec
Had a fun flake hunting session thanks to @olleolleolle teeing me up with a RSpec bisect repro.
The flaky test basically did
x = double(:bucket).as_null_object
x.fields
This would sometimes raise “unknown encoding name - #[Double :bucket]”.
Enabling full #RSpec backtraces showed that the error was from… FormHelper.
Turned out a view component spec indirectly did `Object.include(ActionView::Helpers::FormHelper)` which includes methods like `fields` in every object, including doubles.