]> cat aescling's git repositories - mastodon.git/commitdiff
Introduce capybara and first feature spec (#1801)
authorChad Pytel <chad@thoughtbot.com>
Fri, 14 Apr 2017 23:21:02 +0000 (19:21 -0400)
committerEugen <eugen@zeonfederated.com>
Fri, 14 Apr 2017 23:21:02 +0000 (01:21 +0200)
This commit introduces Capybara and the first feature spec.

I focused on coverage for log in for the first feature spec because that would
have prevented 624a9a7136159d460228a0c2f5df18a9ead3b7f2 causing #1236.

Gemfile
Gemfile.lock
spec/features/log_in_spec.rb [new file with mode: 0644]
spec/rails_helper.rb

diff --git a/Gemfile b/Gemfile
index 3f80e92e10e350dd1a6f826850a023e6f5038e84..d1a1e32349d1bade341a73042fa35951185ee8f6 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -70,6 +70,7 @@ group :development, :test do
 end
 
 group :test do
+  gem 'capybara'
   gem 'faker'
   gem 'rails-controller-testing'
   gem 'rspec-sidekiq'
index 2618f47f2fd23ca58f9969369df5bfe2db9e859e..430e204404055557cf08fc77c10aa71084f4efb5 100644 (file)
@@ -99,6 +99,13 @@ GEM
       sshkit (~> 1.3)
     capistrano-yarn (2.0.2)
       capistrano (~> 3.0)
+    capybara (2.13.0)
+      addressable
+      mime-types (>= 1.16)
+      nokogiri (>= 1.3.3)
+      rack (>= 1.0.0)
+      rack-test (>= 0.5.4)
+      xpath (~> 2.0)
     chunky_png (1.3.8)
     climate_control (0.1.0)
     cocaine (0.5.8)
@@ -446,6 +453,8 @@ GEM
     websocket-driver (0.6.5)
       websocket-extensions (>= 0.1.0)
     websocket-extensions (0.1.2)
+    xpath (2.0.0)
+      nokogiri (~> 1.3)
 
 PLATFORMS
   ruby
@@ -465,6 +474,7 @@ DEPENDENCIES
   capistrano-rails
   capistrano-rbenv
   capistrano-yarn
+  capybara
   coffee-rails (~> 4.1.0)
   devise
   devise-two-factor
diff --git a/spec/features/log_in_spec.rb b/spec/features/log_in_spec.rb
new file mode 100644 (file)
index 0000000..4a634f6
--- /dev/null
@@ -0,0 +1,16 @@
+require "rails_helper"
+
+feature "Log in" do
+  scenario "A valid email and password user is able to log in" do
+    email = "test@example.com"
+    password = "password"
+    Fabricate(:user, email: email, password: password)
+
+    visit new_user_session_path
+    fill_in "user_email", with: email
+    fill_in "user_password", with: password
+    click_on "Log in"
+
+    expect(page).to have_css "div.app-holder[data-react-class=Mastodon]"
+  end
+end
index faac96982d096ce319929ba113d8a2602b3088b1..536c5a7744a33aba3b3d0da957f3579b243c8fc0 100644 (file)
@@ -7,6 +7,7 @@ require 'spec_helper'
 require 'rspec/rails'
 require 'webmock/rspec'
 require 'paperclip/matchers'
+require 'capybara/rspec'
 
 Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
 
@@ -24,6 +25,11 @@ RSpec.configure do |config|
   config.include Devise::Test::ControllerHelpers, type: :controller
   config.include Devise::TestHelpers, type: :view
   config.include Paperclip::Shoulda::Matchers
+
+  config.before :each, type: :feature do
+    https = ENV['LOCAL_HTTPS'] == 'true'
+    Capybara.app_host = "http#{https ? 's' : ''}://#{ENV.fetch('LOCAL_DOMAIN')}"
+  end
 end
 
 RSpec::Sidekiq.configure do |config|