devise_specs 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 81d919f6bedb5fd92fa4c892518b62f68fc888cce3a85c8f668870507bee10c9
4
+ data.tar.gz: dcf1599ab23ca4ba5774701c0561bde7465f0d5b9f9d52603c85bf404290cb4c
5
+ SHA512:
6
+ metadata.gz: 3073813fd46d908597a3ccbe2346cc0b21183602263531993bcb07f7615024c95e7d50583e60bf915af1e3d7f60361c6f23d230f61ebc072c680ced4db444b10
7
+ data.tar.gz: 9aeba75a355fa2e5a66ae238e2f1b28eefbcfea6af453e30dbf090d030e88051c9e7c7f1a97d74fb9764ff4a0a6f0ab472234da0da167c03d49bb54a4d06d7cb
data/.codeclimate.yml ADDED
@@ -0,0 +1,18 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ exclude_fingerprints:
9
+ - 3b39f38c33cdc3b6dc57a5d8160f707b
10
+ fixme:
11
+ enabled: true
12
+ rubocop:
13
+ enabled: true
14
+ ratings:
15
+ paths:
16
+ - "**.rb"
17
+ exclude_paths:
18
+ - features/
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ ### 0.0.4
2
+
3
+ * Make internal tests pass on Rails 5.1 and clean up docs
4
+
5
+
6
+ ### 0.0.3
7
+
8
+ * Use the new `Devise::Test::IntegrationHelpers` instead of the custom `sign_in` helper
9
+
10
+ ### 0.0.2
11
+
12
+ * Add more thorough expectations to generated specs
13
+ * Rename specs:devise generator to devise:specs
14
+ * Update README with Output and Testing sections
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # devise_specs
2
+
3
+ devise_specs is a Rails generator that adds the Devise authentication acceptance tests when you run the `devise` generator. The tests are RSpec feature specs containing Factory Bot or Fabrication fixture replacement methods and Capybara actions.
4
+
5
+ Generated feature specs test the following features:
6
+ * Registration
7
+ * Login
8
+ * Logout
9
+ * Password reset
10
+
11
+ Works with Rails 6+.
12
+
13
+ ## Installation
14
+
15
+ Make sure `devise_specs`, `devise`, `rspec-rails`, `capybara` and fixture replacement gems are added to the `Gemfile`:
16
+ ```ruby
17
+ gem 'devise'
18
+
19
+ group :development do
20
+ gem 'devise_specs'
21
+ end
22
+
23
+ group :test do
24
+ gem 'capybara'
25
+ end
26
+
27
+ group :development, :test do
28
+ gem 'rspec-rails'
29
+ gem 'factory_bot_rails' # or: gem 'fabrication'
30
+ end
31
+ ```
32
+
33
+ and then run `bundle install`.
34
+
35
+ ## Setup
36
+
37
+ Generate the RSpec configuratoin files:
38
+ ```
39
+ $ rails generate rspec:install
40
+ ```
41
+
42
+ Generate the Devise configuration files and follow the setup instructions to define the default url options, root route and flash messages:
43
+ ```
44
+ $ rails generate devise:install
45
+ ```
46
+
47
+ Configure the Action Mailer URL options for the test environment using the following line in `config/environments/test.rb`:
48
+ ```ruby
49
+ config.action_mailer.default_url_options = { host: 'localhost', port: 3001 }
50
+ ```
51
+
52
+ Add the authentication links to the layout, `user_signed_in?` should be `admin_signed_in?` if your Devise model is `Admin`:
53
+ ```erb
54
+ <% if user_signed_in? %>
55
+ <%= link_to 'Sign Out', destroy_user_session_path, method: :delete %>
56
+ <% else %>
57
+ <%= link_to 'Sign In', new_user_session_path %>
58
+ <%= link_to 'Sign Up', new_user_registration_path %>
59
+ <% end %>
60
+ ```
61
+
62
+ ## Usage
63
+
64
+ Specs are created automatically when you generate a Devise model, e.g. `User`:
65
+ ```
66
+ $ rails generate devise User
67
+ ...
68
+ invoke specs
69
+ gsub spec/rails_helper.rb
70
+ insert spec/factories/users.rb
71
+ create spec/support/factory_bot.rb
72
+ create spec/support/devise.rb
73
+ create spec/features/user_signs_up_spec.rb
74
+ create spec/features/user_signs_in_spec.rb
75
+ create spec/features/user_signs_out_spec.rb
76
+ create spec/features/user_resets_password_spec.rb
77
+ ```
78
+
79
+ If a Devise model is already present, run the `devise:specs` generator directly:
80
+ ```
81
+ $ rails generate devise:specs User
82
+ ```
83
+
84
+ Run the migrations:
85
+ ```
86
+ $ rake db:migrate RAILS_ENV=test
87
+ ```
88
+
89
+ Make sure the specs pass:
90
+ ```
91
+ $ rspec spec/features
92
+ .........
93
+
94
+ Finished in 1.08 seconds (files took 2.1 seconds to load)
95
+ 9 examples, 0 failures
96
+ ```
97
+
98
+ ## Documentation
99
+
100
+ Visit the [Relish docs](https://relishapp.com/andrii/devise_specs/docs) for all the available features and examples of the generated feature specs.
101
+
102
+ ## Output
103
+
104
+ `gsub spec/rails_helper.rb`
105
+
106
+ Uncomments the line that auto-requires all files in the support directory.
107
+
108
+ `insert spec/fabricators/*_fabricator.rb`
109
+
110
+ Adds `email` and `password` attributes to the fabricator.
111
+
112
+ `insert spec/factories/*.rb`
113
+
114
+ Adds `email` and `password` attributes to the factory.
115
+
116
+ `create spec/support/factory_bot.rb`
117
+
118
+ Includes `FactoryBot::Syntax::Methods` into RSpec config to avoid prefacing Factory Bot methods with `FactoryBot`.
119
+
120
+ `create spec/support/devise.rb`
121
+
122
+ Includes Devise integration test helpers into feature specs.
123
+
124
+ `create spec/features/*_spec.rb`
125
+
126
+ Generates a corresponding feature spec.
127
+
128
+ ## Testing
129
+
130
+ Install Ruby, development tools, Nokogiri, SQLite and JavaScript runtime system dependencies.
131
+
132
+ On Ubuntu/Mint/Debian:
133
+ ```
134
+ $ apt-get install ruby-full build-essential zlib1g-dev libsqlite3-dev nodejs
135
+ ```
136
+
137
+ Install development dependencies with `bundle install` and run the tests:
138
+ ```
139
+ $ bundle exec rake
140
+ ```
141
+
142
+ ## License
143
+
144
+ MIT License
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'cucumber/rake/task'
2
+
3
+ Cucumber::Rake::Task.new
4
+
5
+ task default: :cucumber
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'devise_specs'
3
+ s.version = '0.0.5'
4
+ s.authors = ["Gaspard d'Hautefeuille"]
5
+ s.email = 'ruby@dhautefeuille.eu'
6
+ s.summary = 'Generates the Devise acceptance tests.'
7
+ s.homepage = 'https://github.com/HLFH/devise_specs'
8
+ s.license = 'MIT'
9
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features|fixtures)/}) }
10
+
11
+ s.required_ruby_version = '>= 2.6.5'
12
+
13
+ s.add_runtime_dependency 'devise', '~> 4.7', '>= 4.7.1'
14
+
15
+ s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
16
+ s.add_development_dependency 'aruba', '~> 1.0'
17
+ end
@@ -0,0 +1,11 @@
1
+ module Devise
2
+ module Specs
3
+ class Railtie < Rails::Railtie
4
+ generators do
5
+ require 'generators/devise/devise_generator'
6
+
7
+ Devise::Generators::DeviseGenerator.hook_for :specs, type: :boolean, default: true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ require 'devise/specs/railtie'
@@ -0,0 +1,71 @@
1
+ module Devise
2
+ module Generators
3
+ class SpecsGenerator < Rails::Generators::NamedBase
4
+ ATTRIBUTES = %(
5
+ email 'username@example.com'
6
+ password 'password')
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+
10
+ def require_supporting_files
11
+ uncomment_lines 'spec/rails_helper.rb', /spec.support.*rb.*require/
12
+ end
13
+
14
+ def insert_fixture_replacement_attributes
15
+ return if behavior == :revoke
16
+
17
+ if fixture_replacement == :factory_bot
18
+ insert_factory_bot_attributes
19
+ elsif fixture_replacement == :fabrication
20
+ insert_fabrication_attributes
21
+ end
22
+ end
23
+
24
+ def create_factory_bot_config_file
25
+ if fixture_replacement == :factory_bot
26
+ template 'factory_bot.rb', 'spec/support/factory_bot.rb'
27
+ end
28
+ end
29
+
30
+ def create_devise_config_file
31
+ template 'devise.rb', 'spec/support/devise.rb'
32
+ end
33
+
34
+ def create_specs
35
+ template 'resource_signs_up_spec.rb',
36
+ "spec/features/#{singular_name}_signs_up_spec.rb"
37
+
38
+ template 'resource_signs_in_spec.rb',
39
+ "spec/features/#{singular_name}_signs_in_spec.rb"
40
+
41
+ template 'resource_signs_out_spec.rb',
42
+ "spec/features/#{singular_name}_signs_out_spec.rb"
43
+
44
+ template 'resource_resets_password_spec.rb',
45
+ "spec/features/#{singular_name}_resets_password_spec.rb"
46
+ end
47
+
48
+ private
49
+
50
+ def fixture_replacement
51
+ Rails.application.config.generators.rails[:fixture_replacement]
52
+ end
53
+
54
+ def insert_factory_bot_attributes
55
+ path = "spec/factories/#{plural_name}.rb"
56
+ attrs = ATTRIBUTES.gsub(/^ {4}/, '')
57
+ data = "factory :#{singular_name} do"
58
+
59
+ create_file path, data + attrs
60
+ end
61
+
62
+ def insert_fabrication_attributes
63
+ path = "spec/fabricators/#{singular_name}_fabricator.rb"
64
+ attrs = ATTRIBUTES.gsub(/^ {6}/, '')
65
+ after = "Fabricator(:#{singular_name}) do"
66
+
67
+ create_file path, data + attrs
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.include Devise::Test::IntegrationHelpers, type: :feature
3
+ end
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.include FactoryBot::Syntax::Methods
3
+ end
@@ -0,0 +1,55 @@
1
+ require 'rails_helper'
2
+
3
+ feature '<%= human_name %> resets a password' do
4
+ scenario '<%= singular_name %> enters a valid email' do
5
+ <% if fixture_replacement == :factory_bot -%>
6
+ <%= singular_name %> = create :<%= singular_name %>
7
+ <% elsif fixture_replacement == :fabrication -%>
8
+ <%= singular_name %> = Fabricate :<%= singular_name %>
9
+ <% end -%>
10
+
11
+ visit new_<%= singular_name %>_password_path
12
+
13
+ fill_in 'Email', with: <%= singular_name %>.email
14
+ click_button 'Send me reset password instructions'
15
+
16
+ expect(page).to have_text 'You will receive an email with instructions'
17
+ expect(page).to have_current_path new_<%= singular_name %>_session_path
18
+ end
19
+
20
+ scenario '<%= singular_name %> enters an invalid email' do
21
+ visit new_<%= singular_name %>_password_path
22
+
23
+ fill_in 'Email', with: 'username@example.com'
24
+ click_button 'Send me reset password instructions'
25
+
26
+ expect(page).to have_text 'Email not found'
27
+ end
28
+
29
+ scenario '<%= singular_name %> changes password' do
30
+ <% if fixture_replacement == :factory_bot -%>
31
+ token = create(:<%= singular_name %>).send_reset_password_instructions
32
+ <% elsif fixture_replacement == :fabrication -%>
33
+ token = Fabricate(:<%= singular_name %>).send_reset_password_instructions
34
+ <% end -%>
35
+
36
+ visit edit_<%= singular_name %>_password_path(reset_password_token: token)
37
+
38
+ fill_in 'New password', with: 'p4ssw0rd'
39
+ fill_in 'Confirm new password', with: 'p4ssw0rd'
40
+ click_button 'Change my password'
41
+
42
+ expect(page).to have_text 'Your password has been changed successfully.'
43
+ expect(page).to have_current_path root_path
44
+ end
45
+
46
+ scenario 'password reset token is invalid' do
47
+ visit edit_<%= singular_name %>_password_path(reset_password_token: 'token')
48
+
49
+ fill_in 'New password', with: 'p4ssw0rd'
50
+ fill_in 'Confirm new password', with: 'p4ssw0rd'
51
+ click_button 'Change my password'
52
+
53
+ expect(page).to have_text 'Reset password token is invalid'
54
+ end
55
+ end
@@ -0,0 +1,38 @@
1
+ require 'rails_helper'
2
+
3
+ feature '<%= human_name %> signs in' do
4
+ scenario 'with valid credentials' do
5
+ <% if fixture_replacement == :factory_bot -%>
6
+ <%= singular_name %> = create :<%= singular_name %>
7
+ <% elsif fixture_replacement == :fabrication -%>
8
+ <%= singular_name %> = Fabricate :<%= singular_name %>
9
+ <% end -%>
10
+
11
+ visit new_<%= singular_name %>_session_path
12
+
13
+ fill_in 'Email', with: <%= singular_name %>.email
14
+ fill_in 'Password', with: <%= singular_name %>.password
15
+ click_button 'Log in'
16
+
17
+ expect(page).to have_text 'Signed in successfully.'
18
+ expect(page).to have_link 'Sign Out'
19
+ expect(page).to have_current_path root_path
20
+ end
21
+
22
+ scenario 'with invalid credentials' do
23
+ <% if fixture_replacement == :factory_bot -%>
24
+ <%= singular_name %> = build :<%= singular_name %>
25
+ <% elsif fixture_replacement == :fabrication -%>
26
+ <%= singular_name %> = Fabricate.build :<%= singular_name %>
27
+ <% end -%>
28
+
29
+ visit new_<%= singular_name %>_session_path
30
+
31
+ fill_in 'Email', with: <%= singular_name %>.email
32
+ fill_in 'Password', with: <%= singular_name %>.password
33
+ click_button 'Log in'
34
+
35
+ expect(page).to have_text 'Invalid Email or password.'
36
+ expect(page).to have_no_link 'Sign Out'
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ require 'rails_helper'
2
+
3
+ feature '<%= human_name %> signs out' do
4
+ scenario '<%= singular_name %> signed in' do
5
+ <% if fixture_replacement == :factory_bot -%>
6
+ <%= singular_name %> = create :<%= singular_name %>
7
+ <% elsif fixture_replacement == :fabrication -%>
8
+ <%= singular_name %> = Fabricate :<%= singular_name %>
9
+ <% end -%>
10
+
11
+ sign_in <%= singular_name %>
12
+
13
+ visit root_path
14
+
15
+ click_link 'Sign Out'
16
+
17
+ expect(page).to have_text 'Signed out successfully.'
18
+ expect(page).to have_no_link 'Sign Out'
19
+ expect(page).to have_current_path root_path
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails_helper'
2
+
3
+ feature '<%= human_name %> signs up' do
4
+ scenario 'with valid data' do
5
+ visit new_<%= singular_name %>_registration_path
6
+
7
+ fill_in 'Email', with: 'username@example.com'
8
+ fill_in 'Password', with: 'password'
9
+ fill_in 'Password confirmation', with: 'password'
10
+ click_button 'Sign up'
11
+
12
+ expect(page).to have_text 'Welcome! You have signed up successfully.'
13
+ expect(page).to have_link 'Sign Out'
14
+ expect(page).to have_current_path root_path
15
+ end
16
+
17
+ scenario 'with invalid data' do
18
+ visit new_<%= singular_name %>_registration_path
19
+
20
+ click_button 'Sign up'
21
+
22
+ expect(page).to have_text "Email can't be blank"
23
+ expect(page).to have_text "Password can't be blank"
24
+ expect(page).to have_no_link 'Sign Out'
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_specs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Gaspard d'Hautefeuille
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devise
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.7.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.7'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.7.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 13.0.1
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '13.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 13.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: aruba
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.0'
67
+ description:
68
+ email: ruby@dhautefeuille.eu
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - ".codeclimate.yml"
74
+ - ".gitignore"
75
+ - ".travis.yml"
76
+ - CHANGELOG.md
77
+ - Gemfile
78
+ - README.md
79
+ - Rakefile
80
+ - devise_specs.gemspec
81
+ - lib/devise/specs/railtie.rb
82
+ - lib/devise_specs.rb
83
+ - lib/generators/devise/specs_generator.rb
84
+ - lib/generators/devise/templates/devise.rb.tt
85
+ - lib/generators/devise/templates/factory_bot.rb.tt
86
+ - lib/generators/devise/templates/resource_resets_password_spec.rb.tt
87
+ - lib/generators/devise/templates/resource_signs_in_spec.rb.tt
88
+ - lib/generators/devise/templates/resource_signs_out_spec.rb.tt
89
+ - lib/generators/devise/templates/resource_signs_up_spec.rb.tt
90
+ homepage: https://github.com/HLFH/devise_specs
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.6.5
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.1.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Generates the Devise acceptance tests.
113
+ test_files: []