utensils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +22 -0
- data/Rakefile +2 -0
- data/lib/utensils/capybara_extensions.rb +10 -0
- data/lib/utensils/custom_matchers.rb +163 -0
- data/lib/utensils/database_cleaner.rb +11 -0
- data/lib/utensils/upload_macros.rb +15 -0
- data/lib/utensils/vcr.rb +18 -0
- data/lib/utensils/version.rb +3 -0
- data/lib/utensils.rb +5 -0
- data/utensils.gemspec +17 -0
- metadata +58 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jens Balvig
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Utensils
|
2
|
+
|
3
|
+
Rspec stuff we use over and over again
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'utensils'
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
1. Create a utensils.rb file in spec/support
|
14
|
+
2. Add whichever bits you need:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'utensils/custom_matchers'
|
18
|
+
require 'utensils/upload_macros'
|
19
|
+
require 'utensils/capybara_extensions'
|
20
|
+
require 'utensils/database_cleaner'
|
21
|
+
require 'utensils/vcr'
|
22
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
module Utensils
|
2
|
+
module CustomMatchers
|
3
|
+
class HaveModel
|
4
|
+
def initialize(model)
|
5
|
+
@model_id = ApplicationController.helpers.dom_id(model)
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(page)
|
9
|
+
@page = page
|
10
|
+
@page.has_css?("##{@model_id}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure_message_for_should
|
14
|
+
"expected #{@page.body} to contain element with id: #{@model_id}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure_message_for_should_not
|
18
|
+
"expected #{@page.body} to not contain element with id: #{@model_id}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def have_model(model)
|
23
|
+
HaveModel.new(model)
|
24
|
+
end
|
25
|
+
|
26
|
+
class HaveNoModel
|
27
|
+
def initialize(model)
|
28
|
+
@model_id = ApplicationController.helpers.dom_id(model)
|
29
|
+
end
|
30
|
+
|
31
|
+
def matches?(page)
|
32
|
+
@page = page
|
33
|
+
@page.has_no_css?("##{@model_id}")
|
34
|
+
end
|
35
|
+
|
36
|
+
def failure_message_for_should
|
37
|
+
"expected #{@page.body} to not contain element with id: #{@model_id}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def failure_message_for_should_not
|
41
|
+
"expected #{@page.body} to contain element with id: #{@model_id}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def have_no_model(model)
|
46
|
+
HaveNoModel.new(model)
|
47
|
+
end
|
48
|
+
|
49
|
+
class HaveClass
|
50
|
+
def initialize(class_name)
|
51
|
+
@class_name = class_name
|
52
|
+
end
|
53
|
+
|
54
|
+
def matches?(element)
|
55
|
+
@element = element
|
56
|
+
@element[:class] == @class_name
|
57
|
+
end
|
58
|
+
|
59
|
+
def failure_message_for_should
|
60
|
+
"expected #{@element.tag_name} to have class #{@class_name} but had #{@element[:class]}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def failure_message_for_should_not
|
64
|
+
"expected #{@element.tag_name} to not have class #{@class_name} but it did"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def have_class(class_namel)
|
69
|
+
HaveClass.new(class_namel)
|
70
|
+
end
|
71
|
+
|
72
|
+
class Disabled
|
73
|
+
def matches?(element)
|
74
|
+
@element = element
|
75
|
+
@element[:disabled] == "disabled"
|
76
|
+
end
|
77
|
+
|
78
|
+
def failure_message_for_should
|
79
|
+
"expected #{@element.tag_name} to be disabled but it wasn't"
|
80
|
+
end
|
81
|
+
|
82
|
+
def failure_message_for_should_not
|
83
|
+
"expected #{@element.tag_name} not to be disabled but it was"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def disabled?
|
88
|
+
Disabled.new
|
89
|
+
end
|
90
|
+
|
91
|
+
class HaveImage
|
92
|
+
def initialize(image)
|
93
|
+
@image = image
|
94
|
+
end
|
95
|
+
|
96
|
+
def matches?(page)
|
97
|
+
@page = page
|
98
|
+
@image.is_a?(String) ? find_by_url : find_dragonfly_image
|
99
|
+
end
|
100
|
+
|
101
|
+
def failure_message_for_should
|
102
|
+
"expected #{@page.body} to contain image: #{@image.inspect}"
|
103
|
+
end
|
104
|
+
|
105
|
+
def failure_message_for_should_not
|
106
|
+
"expected #{@page.body} to not contain image: #{@image.inspect}"
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def find_by_url
|
112
|
+
@page.has_css?("img[src='#{@image}']")
|
113
|
+
end
|
114
|
+
|
115
|
+
def find_dragonfly_image
|
116
|
+
@page.all('img').each do |img|
|
117
|
+
url = img['src']
|
118
|
+
dragonfly_hash = url[/media\/([^\/.]+)/, 1]
|
119
|
+
if dragonfly_hash
|
120
|
+
dragonfly_job = Dragonfly::Job.deserialize(dragonfly_hash, Dragonfly[:images])
|
121
|
+
return true if dragonfly_job.uid == @image.send(:uid)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
return false
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def have_image(image_url)
|
129
|
+
HaveImage.new(image_url)
|
130
|
+
end
|
131
|
+
|
132
|
+
class Ordered
|
133
|
+
def initialize(args)
|
134
|
+
@within = args.pop[:within]
|
135
|
+
@models = args
|
136
|
+
end
|
137
|
+
|
138
|
+
def matches?(page)
|
139
|
+
@page = page
|
140
|
+
@models.each_with_index do |model,i|
|
141
|
+
return false unless @page.has_css?("#{@within} ##{ApplicationController.helpers.dom_id(model)}:nth-child(#{i+1})")
|
142
|
+
end
|
143
|
+
true
|
144
|
+
end
|
145
|
+
|
146
|
+
def failure_message_for_should
|
147
|
+
"expected #{@page.body} to have models in this order: #{@models.inspect}"
|
148
|
+
end
|
149
|
+
|
150
|
+
def failure_message_for_should_not
|
151
|
+
"expected #{@page.body} to not have models in this order: #{@models.inspect}"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def have_order(*args)
|
156
|
+
Ordered.new(args)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
RSpec.configure do |config|
|
162
|
+
config.include(Utensils::CustomMatchers, :type => :request)
|
163
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Utensils
|
2
|
+
module UploadMacros
|
3
|
+
def fixture_file(filename)
|
4
|
+
File.new(fixture_file_path(filename))
|
5
|
+
end
|
6
|
+
|
7
|
+
def fixture_file_path(filename)
|
8
|
+
Rails.root.join('spec','fixtures',filename)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include(Utensils::UploadMacros)
|
15
|
+
end
|
data/lib/utensils/vcr.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
|
3
|
+
VCR.configure do |config|
|
4
|
+
config.cassette_library_dir = 'spec/fixtures/cassettes'
|
5
|
+
config.hook_into :webmock
|
6
|
+
config.default_cassette_options = {:record => :new_episodes, :preserve_exact_body_bytes => true}
|
7
|
+
config.ignore_localhost = true
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.extend VCR::RSpec::Macros
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
|
14
|
+
config.around(:each, :allow_http) do |example|
|
15
|
+
name = example.metadata[:full_description].underscore.gsub(/[^\w\/]+/, "_")
|
16
|
+
VCR.use_cassette(name) { example.call }
|
17
|
+
end
|
18
|
+
end
|
data/lib/utensils.rb
ADDED
data/utensils.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/utensils/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jens Balvig"]
|
6
|
+
gem.email = ["jens@balvig.com"]
|
7
|
+
gem.description = %q{Rspec stuff we use over and over again}
|
8
|
+
gem.summary = %q{Rspec stuff we use over and over again}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "utensils"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Utensils::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: utensils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jens Balvig
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Rspec stuff we use over and over again
|
15
|
+
email:
|
16
|
+
- jens@balvig.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/utensils.rb
|
27
|
+
- lib/utensils/capybara_extensions.rb
|
28
|
+
- lib/utensils/custom_matchers.rb
|
29
|
+
- lib/utensils/database_cleaner.rb
|
30
|
+
- lib/utensils/upload_macros.rb
|
31
|
+
- lib/utensils/vcr.rb
|
32
|
+
- lib/utensils/version.rb
|
33
|
+
- utensils.gemspec
|
34
|
+
homepage: ''
|
35
|
+
licenses: []
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.11
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Rspec stuff we use over and over again
|
58
|
+
test_files: []
|