How to write a good test description
My logic is very similar to this article https://guilhermesimoes.github.io/blog/writing-good-test-descriptions 其實很簡單,就是 test description...
Fix timestamp precision problem in CI
用 Timecop freeze 時間時,會因為作業系統不同的關係導致 RSpec test 在 compare timestamp 時出現誤差值,導致在 local 能 pass 的 test case 在 CI 卻會 failed,以下提供看似正常但會出錯的 Test ...
Readable feature test with RSpec
可以用更語意的 method 來寫 spec,with `given`, `when`, `and`, `then` keywords Example: ```rb feature 'Enrolment' do scenario 'Enrolling in a c...
FactoryBot build_stubbed, build, and create
- Speed `build_stubbed` > `build` > `ceate` - `build` is not persistent object, `build_stubbed` make object looks like persistent - `buil...
該寫哪些 test?
https://www.codewithjason.com/kinds-rails-tests-write-kinds-dont/ TL;DR: 1. 每個人對 test 的名稱定義不一樣,有些人叫 acceptance, 有些人叫 end to end, integr...
Faking External Services in Tests with Adapters
Faking External Services in Tests with Adapters https://thoughtbot.com/blog/faking-external-services-in-tests-with-adapters
How to test ActionMailer with RSpec
This blog post will demostrate how to test ActionMailer in Rails using RSpec. ## Configuration ```rb # config/environments/test.rb # T...
How to test Stripe webhook's singature with Rspec
This post shows how to test Stripe webhook's singature ```rb # spec/support/stripe_test_helper.rb module StripeTestHelper def stripe_...
rspec test protocal (interface) - part 1 - define what's interface and find it
通常我們會希望繼承於 Base class 底下的 class 會有相同的 interface,for example, 每個 service 都要有一個 #call 的 instance method,應該要有個很簡單的方法來對這些 services 測試是否有 imp...
Rspec aggregate_failures syntax
意思就是在 aggregate_failures block 底下任一個的 expectation 有 error 時會針對每個 expectation 顯示 error 的 message example ```ruby it "returns false ...
great feature spec example
```rb feature 'User views all books' do scenario 'list all books' do create(:book, title: 'Practical Vim') create(:book, titl...
看到一個不錯的 mock example (RSpec)
之前一篇文章提到 RSpec 盡量不用 let, 那要用啥?可以用 method。 另外看到一個不錯的 mock example, 用 tap 來 return double 但是 yield Authentictor ```rb def stub_authentica...
RSpec best practice
https://github.com/thoughtbot/guides/tree/dee16052f49cb4b41fb8d090ffdb75942512ddb1/best-practices#testing https://robots.thoughtbot.c...
FactoryGirl 原來還可以在 factory 下面再用 factory
FactoryGirl 原來還可以在 factory 下面再用 factory 這樣就可以用 ``` create(:tiny_btc_account) ``` ``` FactoryGirl.define do factory :account do l...