diff --git a/Gemfile b/Gemfile index 700b652..3da3fd7 100644 --- a/Gemfile +++ b/Gemfile @@ -77,6 +77,8 @@ group :development, :test do gem 'codecov', '~> 0.1.17', require: false # Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing. gem 'database_cleaner', '~> 1.8.5' + # Capybara is an integration testing tool for rack based web applications. It simulates how a user would interact with a website + gem 'capybara' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index afb8a0f..332e0e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,8 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) ansi (1.5.0) arel (9.0.0) autoprefixer-rails (9.8.6.3) @@ -52,6 +54,14 @@ GEM msgpack (~> 1.0) builder (3.2.4) byebug (11.1.3) + capybara (3.33.0) + addressable + mini_mime (>= 0.1.3) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) codecov (0.1.21) json simplecov @@ -120,6 +130,7 @@ GEM mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) pg (1.2.3) + public_suffix (4.0.6) puma (3.12.6) rack (2.2.3) rack-test (1.1.0) @@ -156,6 +167,7 @@ GEM rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) + regexp_parser (1.8.2) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) @@ -243,6 +255,8 @@ GEM websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) will_paginate (3.1.8) + xpath (3.2.0) + nokogiri (~> 1.8) PLATFORMS ruby @@ -250,6 +264,7 @@ PLATFORMS DEPENDENCIES bootsnap (>= 1.1.0) byebug + capybara codecov (~> 0.1.17) coffee-rails (~> 4.2) database_cleaner (~> 1.8.5) diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb new file mode 100644 index 0000000..7e11aaa --- /dev/null +++ b/spec/features/users_spec.rb @@ -0,0 +1,49 @@ +require 'rails_helper' + +RSpec.feature "Users", type: :feature do + context 'create new user' do + scenario "should be successful" do + visit new_user_registration_path + within('form') do + fill_in 'Email', with: 'john.doe@example.com' + fill_in 'Password', with: 'examplePass' + fill_in 'Password confirmation', with: 'examplePass' + end + click_button 'Sign up' + expect(page).to have_content('Logout john.doe@example.com') + end + + scenario "should fail" do + visit new_user_registration_path + within('form') do + end + click_button 'Sign up' + expect(page).to have_content('Email can\'t be blank Password can\'t be blank') + end + + scenario "should fail password doesen\'t mutch password" do + visit new_user_registration_path + within('form') do + fill_in 'Email', with: 'john.doe@example.com' + fill_in 'Password', with: 'examplePass' + end + click_button 'Sign up' + expect(page).to have_content('Password confirmation doesn\'t match Password') + end + + scenario "should redirect to Log in page" do + visit new_user_registration_path + within('form') do + fill_in 'Email', with: 'john.doe@example.com' + fill_in 'Password', with: 'examplePass' + end + # click_link 'Log in' + find("a[href='#{new_user_registration_path}']").click + expect(page).to have_content('Log in') + end + end + context 'update user' do + end + context 'destroy user' do + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 2ba5ec1..73a4220 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -5,6 +5,7 @@ # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' +require 'capybara/rails' # Add additional requires below this line. Rails is not loaded until this point! require 'support/factory_bot' require 'support/simple_cov'