dragonfly 0.8.6 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of dragonfly might be problematic. Click here for more details.
- data/{.specopts → .rspec} +0 -1
- data/.yardopts +6 -2
- data/Gemfile +14 -13
- data/History.md +47 -9
- data/README.md +25 -5
- data/Rakefile +37 -79
- data/VERSION +1 -1
- data/dragonfly.gemspec +140 -89
- data/extra_docs/Analysers.md +8 -48
- data/extra_docs/Configuration.md +40 -25
- data/extra_docs/Couch.md +49 -0
- data/extra_docs/DataStorage.md +94 -24
- data/extra_docs/Encoding.md +6 -35
- data/extra_docs/ExampleUseCases.md +113 -0
- data/extra_docs/GeneralUsage.md +7 -23
- data/extra_docs/Generators.md +15 -49
- data/extra_docs/Heroku.md +7 -8
- data/extra_docs/ImageMagick.md +126 -0
- data/extra_docs/MimeTypes.md +3 -3
- data/extra_docs/Models.md +163 -0
- data/extra_docs/Mongo.md +1 -4
- data/extra_docs/Processing.md +7 -60
- data/extra_docs/Rails2.md +3 -1
- data/extra_docs/Rails3.md +2 -10
- data/extra_docs/ServingRemotely.md +83 -0
- data/extra_docs/Sinatra.md +3 -3
- data/extra_docs/URLs.md +60 -33
- data/features/rails_3.0.5.feature +8 -0
- data/features/steps/rails_steps.rb +7 -18
- data/features/support/env.rb +10 -37
- data/features/support/setup.rb +32 -0
- data/fixtures/rails_3.0.5/files/app/models/album.rb +5 -0
- data/fixtures/rails_3.0.5/files/app/views/albums/new.html.erb +7 -0
- data/fixtures/{files → rails_3.0.5/files}/app/views/albums/show.html.erb +2 -0
- data/fixtures/{files → rails_3.0.5/files}/config/initializers/dragonfly.rb +0 -0
- data/fixtures/rails_3.0.5/files/features/manage_album_images.feature +38 -0
- data/fixtures/rails_3.0.5/files/features/step_definitions/helper_steps.rb +7 -0
- data/fixtures/{files → rails_3.0.5/files}/features/step_definitions/image_steps.rb +11 -1
- data/fixtures/{files → rails_3.0.5/files}/features/support/paths.rb +2 -0
- data/fixtures/{files → rails_3.0.5/files}/features/text_images.feature +0 -0
- data/fixtures/{rails_3.0.3 → rails_3.0.5}/template.rb +2 -2
- data/irbrc.rb +2 -1
- data/lib/dragonfly.rb +7 -0
- data/lib/dragonfly/active_model_extensions/attachment.rb +134 -46
- data/lib/dragonfly/active_model_extensions/attachment_class_methods.rb +144 -0
- data/lib/dragonfly/active_model_extensions/class_methods.rb +62 -9
- data/lib/dragonfly/active_model_extensions/instance_methods.rb +2 -2
- data/lib/dragonfly/active_model_extensions/validations.rb +10 -6
- data/lib/dragonfly/analyser.rb +0 -1
- data/lib/dragonfly/analysis/file_command_analyser.rb +1 -1
- data/lib/dragonfly/analysis/image_magick_analyser.rb +2 -43
- data/lib/dragonfly/app.rb +64 -55
- data/lib/dragonfly/config/heroku.rb +1 -1
- data/lib/dragonfly/config/image_magick.rb +2 -37
- data/lib/dragonfly/config/rails.rb +5 -2
- data/lib/dragonfly/configurable.rb +115 -35
- data/lib/dragonfly/core_ext/object.rb +1 -1
- data/lib/dragonfly/core_ext/string.rb +1 -1
- data/lib/dragonfly/data_storage/couch_data_store.rb +84 -0
- data/lib/dragonfly/data_storage/file_data_store.rb +43 -18
- data/lib/dragonfly/data_storage/mongo_data_store.rb +8 -4
- data/lib/dragonfly/data_storage/s3data_store.rb +82 -38
- data/lib/dragonfly/encoding/image_magick_encoder.rb +2 -53
- data/lib/dragonfly/function_manager.rb +4 -2
- data/lib/dragonfly/generation/image_magick_generator.rb +2 -136
- data/lib/dragonfly/hash_with_css_style_keys.rb +21 -0
- data/lib/dragonfly/image_magick/analyser.rb +51 -0
- data/lib/dragonfly/image_magick/config.rb +44 -0
- data/lib/dragonfly/{encoding/r_magick_encoder.rb → image_magick/encoder.rb} +10 -14
- data/lib/dragonfly/image_magick/generator.rb +145 -0
- data/lib/dragonfly/image_magick/processor.rb +104 -0
- data/lib/dragonfly/image_magick/utils.rb +72 -0
- data/lib/dragonfly/image_magick_utils.rb +2 -79
- data/lib/dragonfly/job.rb +152 -90
- data/lib/dragonfly/middleware.rb +5 -19
- data/lib/dragonfly/processing/image_magick_processor.rb +2 -95
- data/lib/dragonfly/rails/images.rb +15 -10
- data/lib/dragonfly/response.rb +26 -12
- data/lib/dragonfly/serializer.rb +1 -4
- data/lib/dragonfly/server.rb +103 -0
- data/lib/dragonfly/temp_object.rb +56 -101
- data/lib/dragonfly/url_mapper.rb +78 -0
- data/spec/dragonfly/active_model_extensions/model_spec.rb +772 -65
- data/spec/dragonfly/active_model_extensions/spec_helper.rb +90 -10
- data/spec/dragonfly/analyser_spec.rb +1 -1
- data/spec/dragonfly/analysis/file_command_analyser_spec.rb +5 -14
- data/spec/dragonfly/app_spec.rb +35 -180
- data/spec/dragonfly/configurable_spec.rb +259 -18
- data/spec/dragonfly/core_ext/string_spec.rb +2 -2
- data/spec/dragonfly/core_ext/symbol_spec.rb +1 -1
- data/spec/dragonfly/data_storage/couch_data_store_spec.rb +84 -0
- data/spec/dragonfly/data_storage/file_data_store_spec.rb +149 -22
- data/spec/dragonfly/data_storage/mongo_data_store_spec.rb +21 -2
- data/spec/dragonfly/data_storage/s3_data_store_spec.rb +207 -43
- data/spec/dragonfly/data_storage/{data_store_spec.rb → shared_data_store_examples.rb} +16 -15
- data/spec/dragonfly/function_manager_spec.rb +2 -2
- data/spec/dragonfly/{generation/hash_with_css_style_keys_spec.rb → hash_with_css_style_keys_spec.rb} +2 -2
- data/spec/dragonfly/{analysis/shared_analyser_spec.rb → image_magick/analyser_spec.rb} +19 -6
- data/spec/dragonfly/{encoding/image_magick_encoder_spec.rb → image_magick/encoder_spec.rb} +2 -2
- data/spec/dragonfly/image_magick/generator_spec.rb +172 -0
- data/spec/dragonfly/{processing/shared_processing_spec.rb → image_magick/processor_spec.rb} +55 -6
- data/spec/dragonfly/image_magick/utils_spec.rb +18 -0
- data/spec/dragonfly/job_builder_spec.rb +1 -1
- data/spec/dragonfly/job_definitions_spec.rb +1 -1
- data/spec/dragonfly/job_endpoint_spec.rb +26 -3
- data/spec/dragonfly/job_spec.rb +426 -208
- data/spec/dragonfly/loggable_spec.rb +2 -2
- data/spec/dragonfly/middleware_spec.rb +5 -26
- data/spec/dragonfly/routed_endpoint_spec.rb +1 -1
- data/spec/dragonfly/serializer_spec.rb +1 -14
- data/spec/dragonfly/server_spec.rb +261 -0
- data/spec/dragonfly/simple_cache_spec.rb +1 -1
- data/spec/dragonfly/temp_object_spec.rb +84 -130
- data/spec/dragonfly/url_mapper_spec.rb +130 -0
- data/spec/functional/deprecations_spec.rb +51 -0
- data/spec/functional/image_magick_app_spec.rb +27 -0
- data/spec/functional/model_urls_spec.rb +85 -0
- data/spec/functional/remote_on_the_fly_spec.rb +51 -0
- data/spec/functional/to_response_spec.rb +31 -0
- data/spec/spec_helper.rb +12 -22
- data/spec/{argument_matchers.rb → support/argument_matchers.rb} +0 -0
- data/spec/{image_matchers.rb → support/image_matchers.rb} +4 -4
- data/spec/support/simple_matchers.rb +53 -0
- data/yard/handlers/configurable_attr_handler.rb +2 -2
- data/yard/templates/default/fulldoc/html/css/common.css +12 -10
- data/yard/templates/default/layout/html/layout.erb +6 -0
- metadata +267 -308
- data/Gemfile.rails.2.3.5 +0 -20
- data/features/3.0.3.feature +0 -8
- data/features/rails_2.3.5.feature +0 -7
- data/fixtures/files/app/models/album.rb +0 -3
- data/fixtures/files/app/views/albums/new.html.erb +0 -4
- data/fixtures/files/features/manage_album_images.feature +0 -12
- data/fixtures/rails_2.3.5/template.rb +0 -10
- data/lib/dragonfly/analysis/r_magick_analyser.rb +0 -63
- data/lib/dragonfly/config/r_magick.rb +0 -46
- data/lib/dragonfly/generation/hash_with_css_style_keys.rb +0 -23
- data/lib/dragonfly/generation/r_magick_generator.rb +0 -155
- data/lib/dragonfly/processing/r_magick_processor.rb +0 -126
- data/lib/dragonfly/r_magick_utils.rb +0 -48
- data/lib/dragonfly/simple_endpoint.rb +0 -76
- data/spec/dragonfly/active_model_extensions/active_model_setup.rb +0 -97
- data/spec/dragonfly/active_model_extensions/active_record_setup.rb +0 -85
- data/spec/dragonfly/analysis/image_magick_analyser_spec.rb +0 -15
- data/spec/dragonfly/analysis/r_magick_analyser_spec.rb +0 -31
- data/spec/dragonfly/config/r_magick_spec.rb +0 -29
- data/spec/dragonfly/encoding/r_magick_encoder_spec.rb +0 -41
- data/spec/dragonfly/generation/image_magick_generator_spec.rb +0 -12
- data/spec/dragonfly/generation/r_magick_generator_spec.rb +0 -28
- data/spec/dragonfly/generation/shared_generator_spec.rb +0 -91
- data/spec/dragonfly/image_magick_utils_spec.rb +0 -16
- data/spec/dragonfly/processing/image_magick_processor_spec.rb +0 -29
- data/spec/dragonfly/processing/r_magick_processor_spec.rb +0 -30
- data/spec/dragonfly/simple_endpoint_spec.rb +0 -97
- data/spec/simple_matchers.rb +0 -44
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# Needs: @generator
|
4
|
-
describe "image generator", :shared => true do
|
5
|
-
|
6
|
-
describe "generating an image with the given dimensions" do
|
7
|
-
before(:each) do
|
8
|
-
@image, @extra = @generator.plasma(23,12)
|
9
|
-
end
|
10
|
-
it {@image.should have_width(23)}
|
11
|
-
it {@image.should have_height(12)}
|
12
|
-
it {@image.should have_format('png')}
|
13
|
-
it {@extra.should == {:format => :png, :name => 'plasma.png'}}
|
14
|
-
end
|
15
|
-
|
16
|
-
describe "specifying the format" do
|
17
|
-
before(:each) do
|
18
|
-
@image, @extra = @generator.plasma(23, 12, :gif)
|
19
|
-
end
|
20
|
-
it {@image.should have_format('gif')}
|
21
|
-
it {@extra.should == {:format => :gif, :name => 'plasma.gif'}}
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "text" do
|
25
|
-
before(:each) do
|
26
|
-
@text = "mmm"
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "creating a text image" do
|
30
|
-
before(:each) do
|
31
|
-
@image, @extra = @generator.text(@text, :font_size => 12)
|
32
|
-
end
|
33
|
-
it {@image.should have_width(20..40)} # approximate
|
34
|
-
it {@image.should have_height(10..20)}
|
35
|
-
it {@image.should have_format('png')}
|
36
|
-
it {@extra.should == {:format => :png, :name => 'text.png'}}
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "specifying the format" do
|
40
|
-
before(:each) do
|
41
|
-
@image, @extra = @generator.text(@text, :format => :gif)
|
42
|
-
end
|
43
|
-
it {@image.should have_format('gif')}
|
44
|
-
it {@extra.should == {:format => :gif, :name => 'text.gif'}}
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "padding" do
|
48
|
-
before(:each) do
|
49
|
-
no_padding_text, extra = @generator.text(@text, :font_size => 12)
|
50
|
-
@width = image_properties(no_padding_text)[:width].to_i
|
51
|
-
@height = image_properties(no_padding_text)[:height].to_i
|
52
|
-
end
|
53
|
-
it "1 number shortcut" do
|
54
|
-
image, extra = @generator.text(@text, :padding => '10')
|
55
|
-
image.should have_width(@width + 20)
|
56
|
-
image.should have_height(@height + 20)
|
57
|
-
end
|
58
|
-
it "2 numbers shortcut" do
|
59
|
-
image, extra = @generator.text(@text, :padding => '10 5')
|
60
|
-
image.should have_width(@width + 10)
|
61
|
-
image.should have_height(@height + 20)
|
62
|
-
end
|
63
|
-
it "3 numbers shortcut" do
|
64
|
-
image, extra = @generator.text(@text, :padding => '10 5 8')
|
65
|
-
image.should have_width(@width + 10)
|
66
|
-
image.should have_height(@height + 18)
|
67
|
-
end
|
68
|
-
it "4 numbers shortcut" do
|
69
|
-
image, extra = @generator.text(@text, :padding => '1 2 3 4')
|
70
|
-
image.should have_width(@width + 6)
|
71
|
-
image.should have_height(@height + 4)
|
72
|
-
end
|
73
|
-
it "should override the general padding declaration with the specific one (e.g. 'padding-left')" do
|
74
|
-
image, extra = @generator.text(@text, :padding => '10', 'padding-left' => 9)
|
75
|
-
image.should have_width(@width + 19)
|
76
|
-
image.should have_height(@height + 20)
|
77
|
-
end
|
78
|
-
it "should ignore 'px' suffixes" do
|
79
|
-
image, extra = @generator.text(@text, :padding => '1px 2px 3px 4px')
|
80
|
-
image.should have_width(@width + 6)
|
81
|
-
image.should have_height(@height + 4)
|
82
|
-
end
|
83
|
-
it "bad padding string" do
|
84
|
-
lambda{
|
85
|
-
@generator.text(@text, :padding => '1 2 3 4 5')
|
86
|
-
}.should raise_error(ArgumentError)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dragonfly::ImageMagickUtils do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@obj = Object.new
|
7
|
-
@obj.extend(Dragonfly::ImageMagickUtils)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should raise an error if the identify command isn't found" do
|
11
|
-
lambda{
|
12
|
-
@obj.send(:run, "non-existent-command")
|
13
|
-
}.should raise_error(Dragonfly::ImageMagickUtils::ShellCommandFailed)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'dragonfly/processing/shared_processing_spec'
|
3
|
-
|
4
|
-
describe Dragonfly::Processing::ImageMagickProcessor do
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
|
8
|
-
@image = Dragonfly::TempObject.new(File.new(sample_file))
|
9
|
-
@processor = Dragonfly::Processing::ImageMagickProcessor.new
|
10
|
-
end
|
11
|
-
|
12
|
-
it_should_behave_like "processing methods"
|
13
|
-
|
14
|
-
describe "convert" do
|
15
|
-
it "should allow for general convert commands" do
|
16
|
-
image = @processor.convert(@image, '-scale 56x71')
|
17
|
-
image.should have_width(56)
|
18
|
-
image.should have_height(71)
|
19
|
-
end
|
20
|
-
it "should allow for general convert commands with added format" do
|
21
|
-
image, extra = @processor.convert(@image, '-scale 56x71', :gif)
|
22
|
-
image.should have_width(56)
|
23
|
-
image.should have_height(71)
|
24
|
-
image.should have_format('gif')
|
25
|
-
extra[:format].should == :gif
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
unless ENV['IGNORE_RMAGICK']
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'dragonfly/processing/shared_processing_spec'
|
5
|
-
|
6
|
-
describe Dragonfly::Processing::RMagickProcessor do
|
7
|
-
|
8
|
-
before(:each) do
|
9
|
-
sample_file = File.dirname(__FILE__) + '/../../../samples/beach.png' # 280x355
|
10
|
-
@image = Dragonfly::TempObject.new(File.new(sample_file))
|
11
|
-
@processor = Dragonfly::Processing::RMagickProcessor.new
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "when using the filesystem" do
|
15
|
-
before(:each) do
|
16
|
-
@processor.use_filesystem = true
|
17
|
-
end
|
18
|
-
it_should_behave_like "processing methods"
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "when not using the filesystem" do
|
22
|
-
before(:each) do
|
23
|
-
@processor.use_filesystem = false
|
24
|
-
end
|
25
|
-
it_should_behave_like "processing methods"
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/cache'
|
4
|
-
|
5
|
-
def request(app, path)
|
6
|
-
Rack::MockRequest.new(app).get(path)
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Dragonfly::SimpleEndpoint do
|
10
|
-
|
11
|
-
before(:each) do
|
12
|
-
@app = test_app
|
13
|
-
@app.protect_from_dos_attacks = false
|
14
|
-
@uid = @app.store('HELLO THERE')
|
15
|
-
@endpoint = Dragonfly::SimpleEndpoint.new(@app)
|
16
|
-
end
|
17
|
-
|
18
|
-
after(:each) do
|
19
|
-
@app.destroy(@uid)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should return the thing when given the url" do
|
23
|
-
url = "/#{@app.fetch(@uid).serialize}"
|
24
|
-
response = request(@endpoint, url)
|
25
|
-
response.status.should == 200
|
26
|
-
response.body.should == 'HELLO THERE'
|
27
|
-
response.content_type.should == 'application/octet-stream'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should return a 400 if no sha given but protection on" do
|
31
|
-
@app.protect_from_dos_attacks = true
|
32
|
-
url = "/#{@app.fetch(@uid).serialize}"
|
33
|
-
response = request(@endpoint, url)
|
34
|
-
response.status.should == 400
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should return a 400 if wrong sha given and protection on" do
|
38
|
-
@app.protect_from_dos_attacks = true
|
39
|
-
url = "/#{@app.fetch(@uid).serialize}?s=asdfs"
|
40
|
-
response = request(@endpoint, url)
|
41
|
-
response.status.should == 400
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should return a 404 when the url isn't known" do
|
45
|
-
response = request(@endpoint, '/sadhfasdfdsfsdf')
|
46
|
-
response.status.should == 404
|
47
|
-
response.body.should == 'Not found'
|
48
|
-
response.content_type.should == 'text/plain'
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should return a 404 when the url is a well-encoded but bad array" do
|
52
|
-
url = "/#{Dragonfly::Serializer.marshal_encode([[:egg, {:some => 'args'}]])}"
|
53
|
-
response = request(@endpoint, url)
|
54
|
-
response.status.should == 404
|
55
|
-
response.body.should == 'Not found'
|
56
|
-
response.content_type.should == 'text/plain'
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should return a 403 forbidden when fetch_file is requested" do
|
60
|
-
url = @app.fetch_file('/some/file.txt').url
|
61
|
-
response = request(@endpoint, url)
|
62
|
-
response.status.should == 403
|
63
|
-
response.body.should == 'Forbidden'
|
64
|
-
response.content_type.should == 'text/plain'
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should still work when mapped to a prefix" do
|
68
|
-
endpoint = @endpoint
|
69
|
-
rack_app = Rack::Builder.new do
|
70
|
-
map '/some_prefix' do
|
71
|
-
run endpoint
|
72
|
-
end
|
73
|
-
end.to_app
|
74
|
-
url = "/some_prefix/#{@app.fetch(@uid).serialize}"
|
75
|
-
response = request(rack_app, url)
|
76
|
-
response.status.should == 200
|
77
|
-
response.body.should == 'HELLO THERE'
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should return a simple text response at the root" do
|
81
|
-
response = request(@endpoint, '/')
|
82
|
-
response.status.should == 200
|
83
|
-
response.body.length.should > 0
|
84
|
-
response.content_type.should == 'text/plain'
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should return a cacheable response" do
|
88
|
-
url = "/#{@app.fetch(@uid).serialize}"
|
89
|
-
cache = Rack::Cache.new(@endpoint, :entitystore => 'heap:/')
|
90
|
-
response = request(cache, url)
|
91
|
-
response.status.should == 200
|
92
|
-
response.headers['X-Rack-Cache'].should == "miss, store"
|
93
|
-
response = request(cache, url)
|
94
|
-
response.status.should == 200
|
95
|
-
response.headers['X-Rack-Cache'].should == "fresh"
|
96
|
-
end
|
97
|
-
end
|
data/spec/simple_matchers.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
Spec::Matchers.define :match_url do |url|
|
2
|
-
match do |given|
|
3
|
-
given_path, given_query_string = given.split('?')
|
4
|
-
path, query_string = url.split('?')
|
5
|
-
|
6
|
-
path == given_path && given_query_string.split('&').sort == query_string.split('&').sort
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
Spec::Matchers.define :be_an_empty_directory do
|
11
|
-
match do |given|
|
12
|
-
Dir.entries(given) == ['.','..']
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# The reason we need this is that ActiveRecord 2.x returns just a string/nil, whereas AR 3 always returns an array
|
17
|
-
Spec::Matchers.define :match_ar_error do |string|
|
18
|
-
match do |given|
|
19
|
-
error = given.is_a?(Array) ? given.first : given
|
20
|
-
error == string
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
Spec::Matchers.define :include_hash do |hash|
|
25
|
-
match do |given|
|
26
|
-
given.merge(hash) == given
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def memory_usage
|
31
|
-
GC.start # Garbage collect
|
32
|
-
`ps -o rss= -p #{$$}`.strip.to_i
|
33
|
-
end
|
34
|
-
|
35
|
-
Spec::Matchers.define :leak_memory do
|
36
|
-
match do |given|
|
37
|
-
memory_before = memory_usage
|
38
|
-
given.call
|
39
|
-
memory_after = memory_usage
|
40
|
-
result = memory_after > memory_before
|
41
|
-
puts "#{memory_after} > #{memory_before}" if result
|
42
|
-
result
|
43
|
-
end
|
44
|
-
end
|