expected_responses 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/expected_responses.gemspec +3 -1
- data/lib/expectation_serializer.rb +20 -0
- data/lib/expected_mail.rb +47 -0
- data/lib/expected_responses.rb +59 -0
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/expected_responses.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{expected_responses}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["S\303\251bastien Luquet"]
|
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"expected_responses.gemspec",
|
28
|
+
"lib/expectation_serializer.rb",
|
29
|
+
"lib/expected_mail.rb",
|
28
30
|
"lib/expected_responses.rb",
|
29
31
|
"test/helper.rb",
|
30
32
|
"test/test_expected_responses.rb"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ExpectationSerializer
|
2
|
+
attr_accessor :batch, :output
|
3
|
+
def file_path
|
4
|
+
if respond_to? 'delegate'
|
5
|
+
delegate.class.to_s.split('::').join('/')
|
6
|
+
else
|
7
|
+
self.class.to_s.split('::').join('/')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
def expected_response_root
|
11
|
+
"#{Rails.root}/tmp"
|
12
|
+
end
|
13
|
+
def meth_name
|
14
|
+
if respond_to? 'delegate'
|
15
|
+
delegate.method_name
|
16
|
+
else
|
17
|
+
method_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'shoulda/action_mailer/assertions'
|
2
|
+
module Shoulda # :nodoc:
|
3
|
+
module ActionMailer # :nodoc:
|
4
|
+
module Assertions
|
5
|
+
# Asserts that an email was delivered. Can take a block that can further
|
6
|
+
# narrow down the types of emails you're expecting.
|
7
|
+
#
|
8
|
+
# assert_sent_email
|
9
|
+
#
|
10
|
+
# Passes if ActionMailer::Base.deliveries has an email
|
11
|
+
#
|
12
|
+
# assert_sent_email do |email|
|
13
|
+
# email.subject =~ /hi there/ && email.to.include?('none@none.com')
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# Passes if there is an email with subject containing 'hi there' and
|
17
|
+
# 'none@none.com' as one of the recipients.
|
18
|
+
#
|
19
|
+
def assert_sent_email
|
20
|
+
emails = ::ActionMailer::Base.deliveries
|
21
|
+
assert !emails.empty?, "No emails were sent"
|
22
|
+
if block_given?
|
23
|
+
matching_emails = emails.select {|email| yield email }
|
24
|
+
assert !matching_emails.empty?, "None of the emails matched."
|
25
|
+
end
|
26
|
+
save_mail
|
27
|
+
end
|
28
|
+
include ExpectationSerializer
|
29
|
+
def binary?
|
30
|
+
false
|
31
|
+
end
|
32
|
+
def save_mail path = '', bat = '_'
|
33
|
+
self.output ||= 'expected_responses'
|
34
|
+
format = 'eml'
|
35
|
+
binary = binary? ? "wb" : "w"
|
36
|
+
FileUtils.mkdir_p "#{expected_response_root}/#{output}/#{self.file_path}/" unless File.exists? "#{expected_response_root}/#{output}/#{self.file_path}/"
|
37
|
+
unless batch
|
38
|
+
f = File.new("#{expected_response_root}/#{output}/#{file_path}/#{meth_name}#{path}.#{format}", binary)
|
39
|
+
else
|
40
|
+
f = File.new("#{expected_response_root}/#{output}/#{file_path}/#{meth_name}_#{@request.path_parameters['id']||@request.path_parameters['payment_id']||@request.path_parameters['congress_id']}#{path}.#{format}", binary)
|
41
|
+
end
|
42
|
+
f.write(::ActionMailer::Base.deliveries.last.to_s)
|
43
|
+
f.close
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/expected_responses.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'expectation_serializer'
|
2
|
+
ENV["RAILS_ASSET_ID"] = '' #http://rorl.collectivex.com/discussion/topic/show/26776 & http://maintainable.com/articles/rails_asset_cache pour les cons?quences que cela peut avoir
|
3
|
+
module ActionDispatch
|
4
|
+
module Assertions
|
5
|
+
# A small suite of assertions that test responses from \Rails applications.
|
6
|
+
module ResponseAssertions
|
7
|
+
include ExpectationSerializer
|
8
|
+
def binary?
|
9
|
+
@response.headers['Content-Transfer-Encoding'] == 'binary'
|
10
|
+
end
|
11
|
+
attr_accessor :batch, :output
|
12
|
+
def save_response(type, message = nil, path = '')
|
13
|
+
format = @request.parameters[:format] if @request and @request.parameters
|
14
|
+
self.output||= 'expected_responses' # GetText.locale.to_s == "en" ? 'expected_views' : 'html'
|
15
|
+
format ||= @response.headers['Content-Type'].split(';').first.split('/').first if @response.headers['Content-Type'] and @response.headers['Content-Type'].split('/').last == 'plain'
|
16
|
+
format ||= @response.headers['Content-Disposition'].gsub('"','').split('.').last if @response.headers['Content-Disposition']
|
17
|
+
format ||= @response.headers['type'].split(';').first.split('/').last if binary? and @response.headers['type']
|
18
|
+
format ||= @response.headers['Content-Type'].split(';').first.split('/').last if @response.headers['Content-Type']
|
19
|
+
format ||= 'html'
|
20
|
+
binary = binary? ? "wb" : "w"
|
21
|
+
if type == :success #and ((format == 'application/pdf' and @request.path_parameters['action'] == 'show') or (@request.path_parameters['controller'] == 'sites/registrations'))
|
22
|
+
FileUtils.mkdir_p "#{expected_response_root}/#{output}/#{self.file_path}/" unless File.exists? "#{expected_response_root}/#{output}/#{self.file_path}/"
|
23
|
+
unless batch
|
24
|
+
file_name = "#{expected_response_root}/#{output}/#{file_path}/#{self.meth_name}.#{format}"
|
25
|
+
else
|
26
|
+
file_name = "#{expected_response_root}/#{output}/#{file_path}/#{self.meth_name}_#{@request.path_parameters['id']||@request.path_parameters['payment_id']||@request.path_parameters['congress_id']}.#{format}"
|
27
|
+
end
|
28
|
+
f = File.new(file_name, binary)
|
29
|
+
if format == 'html' and defined? RailsTidy and RailsTidy.tidy_path
|
30
|
+
RailsTidy.filter(@response)
|
31
|
+
end
|
32
|
+
if @response.body.is_a? Proc
|
33
|
+
@response.body.call(@response, f)
|
34
|
+
else
|
35
|
+
f.write(@response.body)
|
36
|
+
end
|
37
|
+
f.close
|
38
|
+
elsif type == :redirect or type == :missing
|
39
|
+
file_name = "#{expected_response_root}/#{output}/#{file_path}/#{self.meth_name}.#{format}"
|
40
|
+
File.delete(file_name) if File.exists? file_name
|
41
|
+
end
|
42
|
+
end
|
43
|
+
def assert_response(type, message = nil)
|
44
|
+
save_response(type, message)
|
45
|
+
validate_request!
|
46
|
+
|
47
|
+
if type.in?([:success, :missing, :redirect, :error]) && @response.send("#{type}?")
|
48
|
+
assert_block("") { true } # to count the assertion
|
49
|
+
elsif type.is_a?(Fixnum) && @response.response_code == type
|
50
|
+
assert_block("") { true } # to count the assertion
|
51
|
+
elsif type.is_a?(Symbol) && @response.response_code == Rack::Utils::SYMBOL_TO_STATUS_CODE[type]
|
52
|
+
assert_block("") { true } # to count the assertion
|
53
|
+
else
|
54
|
+
flunk(build_message(message, "Expected response to be a <?>, but was <?>", type, @response.response_code))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expected_responses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "S\xC3\xA9bastien Luquet"
|
@@ -96,6 +96,8 @@ files:
|
|
96
96
|
- Rakefile
|
97
97
|
- VERSION
|
98
98
|
- expected_responses.gemspec
|
99
|
+
- lib/expectation_serializer.rb
|
100
|
+
- lib/expected_mail.rb
|
99
101
|
- lib/expected_responses.rb
|
100
102
|
- test/helper.rb
|
101
103
|
- test/test_expected_responses.rb
|