Skip to content

Commit

Permalink
".to eq true" を ".to be_truthy" に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
noraworld authored Oct 23, 2024
1 parent 16f6b7a commit 08c1d97
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions articles/capybara-rspec-argument-error.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RSpec.describe '/foo', type: :request do
let(:html) { Capybara.string response.body }

it "displays the flash message" do
expect(html.has_css?('.success', text: 'Field was created successfully')).to eq true
expect(html.has_css?('.success', text: 'Field was created successfully')).to be_truthy
end
end
end
Expand All @@ -86,7 +86,7 @@ end

```diff
- expect(html).to have_css '.success', text: 'Field was created successfully'
+ expect(html.has_css?('.success', text: 'Field was created successfully')).to eq true
+ expect(html.has_css?('.success', text: 'Field was created successfully')).to be_truthy
```

RSpec のマッチャーに関しては詳しく調べていないのですが、どうやらそちら側に問題があるようなので、それを回避するために Capybara 側のマッチャーを使います。上記の例でいうと `have_css` ではなく `has_css?` を使い、`html` ではなく `html.has_css?('.success', text: 'Field was created successfully')``true` を返すかどうかを判定します。
Expand Down

0 comments on commit 08c1d97

Please sign in to comment.