rspec-feature_helpers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +96 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rspec/feature_helpers.rb +39 -0
- data/lib/rspec/feature_helpers/version.rb +5 -0
- data/rspec-feature_helpers.gemspec +25 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db4585ed2d947982695098708cb7a7918c49da46
|
4
|
+
data.tar.gz: 75bcf6a4eab7e15bc5da6d7d03b6367c17630b8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbe45bf9d2fed74c4af61d5d72aa4d9e06501d75cacc0b672ba336bab782d3296ab18836e276a559ff707bc42e9e07623d57a6ed1477f0a2b289aab10f001fc6
|
7
|
+
data.tar.gz: 0dff77e00eab1b51fff6474ad81c95210387c92cef3e2090ff4e3b6fe56bdd1319126b7f19d10c2245145c17362f2ba3fb20bb9f582abfa2050427e539ea32fa
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# RSpec::FeatureHelpers
|
2
|
+
|
3
|
+
This gem aims to allow developers to write focussed spec files by making heavy use of RSpec's memoization and tagging features. This project is intended to be used in the context of testing a Rails application, although it shouldn't strictly depend on it.
|
4
|
+
|
5
|
+
A few things that you get:
|
6
|
+
|
7
|
+
### Automatic login using Warden/Devise
|
8
|
+
|
9
|
+
`Warden::Test::Helpers` get injected into the context of feature specs automatically. Tag your specs with `logged_in` and you get a user logged in automatically prior to specs:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
scenario 'test something', :logged_in do
|
13
|
+
# now your user should be logged in.
|
14
|
+
end
|
15
|
+
```
|
16
|
+
|
17
|
+
The following code is executed as part of a `before` block:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
login_as user
|
21
|
+
```
|
22
|
+
|
23
|
+
In case of using Warden (Devise), the `login_as` method is automatically injected. If you use a different authentication solution, you can still define your own `login_as` method that would log the user in automatically. For example:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
module MyCustomAuthentication
|
27
|
+
def login_as(user)
|
28
|
+
# Do it here...
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.configure do |config|
|
33
|
+
config.include MyCustomAuthentication, type: :feature
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
By default, `user` corresponds to a `create(:user)` block which is what FactoryGirl users use. Again, you can customize what the `user` method lends. You can do this globally or on a per scenario, even a per context basis:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
feature "Administering our site" do
|
41
|
+
background do
|
42
|
+
visit admin_path
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'as an admin', :logged_in do
|
46
|
+
# All scenarios in this given context will
|
47
|
+
# have an admin_user logged in prior to running.
|
48
|
+
let(:user) { create(:admin_user) }
|
49
|
+
|
50
|
+
scenario 'test something' do
|
51
|
+
# ...
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'as a regular user', :logged_in do
|
56
|
+
# All scenarios in this given context will
|
57
|
+
# have a regular user logged in prior to running.
|
58
|
+
|
59
|
+
# This will use the fefault memoized user:
|
60
|
+
# let(:user) { create(:user) }
|
61
|
+
|
62
|
+
scenario 'test soething' do
|
63
|
+
# ...
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
### Using Capybara with a JavaScript capable driver
|
70
|
+
|
71
|
+
The gem also configures Capybara to run all feature tests using a JavaScript capable driver. This might not work for everyone, but I find that having JS errors surfaced as soon as possible is benefitial to testing only business-critical scenarios.
|
72
|
+
|
73
|
+
The gem also cleans up Capybara sessions and reverts it to use the default driver after each feature spec is completed. This way you get a nice and clean state between each spec run.
|
74
|
+
|
75
|
+
## Installation
|
76
|
+
|
77
|
+
Add this line to your application's Gemfile, into the test group:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
group :test do
|
81
|
+
gem 'rspec-feature_helpers'
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
And then execute:
|
86
|
+
|
87
|
+
$ bundle
|
88
|
+
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
1. Fork it ( https://github.com/[my-github-username]/rspec-feature_helpers/fork )
|
93
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
94
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
95
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
96
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/feature_helpers"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "rspec/feature_helpers/version"
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module FeatureHelpers
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
let(:user) { create(:user) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
config.include Warden::Test::Helpers, type: :feature if defined?(Warden)
|
16
|
+
config.include RSpec::FeatureHelpers, type: :feature
|
17
|
+
|
18
|
+
config.before :each, type: :feature, logged_in: true do
|
19
|
+
# Always log in a user prior to running scenarios with 'logged_in' metadata.
|
20
|
+
# You can customize the user instances on a per scenario context by using
|
21
|
+
# RSpec's memoization. For example:
|
22
|
+
#
|
23
|
+
# let(:user) { create(:admin_user) }
|
24
|
+
login_as user
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined?(Capybara)
|
28
|
+
config.before :each, type: :feature do
|
29
|
+
# Always use a JS capable driver when running feature tests
|
30
|
+
Capybara.current_driver = Capybara.javascript_driver
|
31
|
+
end
|
32
|
+
|
33
|
+
config.after :each, type: :feature do
|
34
|
+
# Cleanup after each feature!
|
35
|
+
Capybara.reset_sessions!
|
36
|
+
Capybara.use_default_driver
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec/feature_helpers/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspec-feature_helpers"
|
8
|
+
spec.version = RSpec::FeatureHelpers::VERSION
|
9
|
+
spec.authors = ["Attila Györffy"]
|
10
|
+
spec.email = ["attila@attilagyorffy.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Opinionated RSpec helpers to enhance your feature specs}
|
13
|
+
spec.description = %q{A set of opinionated helpers to enhance testing features using RSpec.}
|
14
|
+
spec.homepage = "http://github.com/liquid/rspec-feature_helpers"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "rspec", ">= 2.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-feature_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Attila Györffy
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: A set of opinionated helpers to enhance testing features using RSpec.
|
56
|
+
email:
|
57
|
+
- attila@attilagyorffy.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/rspec/feature_helpers.rb
|
71
|
+
- lib/rspec/feature_helpers/version.rb
|
72
|
+
- rspec-feature_helpers.gemspec
|
73
|
+
homepage: http://github.com/liquid/rspec-feature_helpers
|
74
|
+
licenses: []
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Opinionated RSpec helpers to enhance your feature specs
|
96
|
+
test_files: []
|