7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails 4.0にcapybara セットアップメモ

Last updated at Posted at 2014-09-11

(Rails 4.0 にturnipセットアップメモの続き)

セットアップ

# Gemfile
group :test, :development do
  gem 'capybara'
end
# spec_helper.rb
require 'turnip/capybara' # turnipで利用する場合

基本系

step 'GETでアクセスする' do
  visit '/login' # GETのみ

  expect(page).to have_content("ほにゃらら")

end
step 'POSTでアクセスする' do
  page.driver.post('/login', {
	username: "ほにゃらら",
    password: "ほにゃらら"
    })

  expect(page).to have_content("ほにゃらら")
end

例外を試験する

step ":url へのルートがない " do |url|
  expect{ visit(url) }.to raise_error(ActionController::RoutingError, "No route matches ほにゃらら")
end

responseがJSONの場合

visit(url)
json = JSON.parse(page.body)

かjson対応のgemをインストールする

メソッドを確認する

session.rb参照

rspecのmatcherを確認する

matchers.rb参照

参考

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?