remnant 0.1.3 → 0.2.0
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.
- data/.rvmrc +1 -0
- data/Gemfile.lock +4 -7
- data/lib/remnant/rails.rb +10 -2
- data/lib/remnant/version.rb +1 -1
- data/spec/app/some/klass.rb +15 -0
- data/spec/app/some/module.rb +9 -0
- data/spec/base_spec.rb +5 -6
- data/spec/discover_spec.rb +64 -0
- data/spec/spec_helper.rb +3 -107
- metadata +9 -2
    
        data/.rvmrc
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            rvm use 1.9.3@gems
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,7 +1,8 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                remnant (0.1.3)
         | 
| 5 | 
            +
                  statsd-ruby (= 1.0.0)
         | 
| 5 6 |  | 
| 6 7 | 
             
            GEM
         | 
| 7 8 | 
             
              remote: http://rubygems.org/
         | 
| @@ -13,7 +14,6 @@ GEM | |
| 13 14 | 
             
                  activesupport (= 2.3.14)
         | 
| 14 15 | 
             
                activesupport (2.3.14)
         | 
| 15 16 | 
             
                diff-lcs (1.1.3)
         | 
| 16 | 
            -
                fakeweb (1.3.0)
         | 
| 17 17 | 
             
                rack (1.1.3)
         | 
| 18 18 | 
             
                rake (0.9.2.2)
         | 
| 19 19 | 
             
                rr (1.0.4)
         | 
| @@ -25,8 +25,7 @@ GEM | |
| 25 25 | 
             
                rspec-expectations (2.11.2)
         | 
| 26 26 | 
             
                  diff-lcs (~> 1.1.3)
         | 
| 27 27 | 
             
                rspec-mocks (2.11.1)
         | 
| 28 | 
            -
                 | 
| 29 | 
            -
                  rack
         | 
| 28 | 
            +
                statsd-ruby (1.0.0)
         | 
| 30 29 |  | 
| 31 30 | 
             
            PLATFORMS
         | 
| 32 31 | 
             
              ruby
         | 
| @@ -35,9 +34,7 @@ DEPENDENCIES | |
| 35 34 | 
             
              actionpack (~> 2.3.8)
         | 
| 36 35 | 
             
              activerecord (~> 2.3.8)
         | 
| 37 36 | 
             
              activesupport (~> 2.3.8)
         | 
| 38 | 
            -
              fakeweb (~> 1.3.0)
         | 
| 39 | 
            -
              flail!
         | 
| 40 37 | 
             
              rake
         | 
| 38 | 
            +
              remnant!
         | 
| 41 39 | 
             
              rr
         | 
| 42 40 | 
             
              rspec
         | 
| 43 | 
            -
              sham_rack (~> 1.3.0)
         | 
    
        data/lib/remnant/rails.rb
    CHANGED
    
    | @@ -44,8 +44,16 @@ class Remnant | |
| 44 44 | 
             
                    ::ActionController::Dispatcher.class_eval do
         | 
| 45 45 | 
             
                      def call_with_remnant_discovery(*args, &block) #:nodoc:
         | 
| 46 46 | 
             
                        call_without_remnant_discovery(*args, &block).tap do |status, headers, response|
         | 
| 47 | 
            -
                           | 
| 48 | 
            -
             | 
| 47 | 
            +
                          begin
         | 
| 48 | 
            +
                            ::Remnant.collect
         | 
| 49 | 
            +
                            ::Rails.logger.flush if ::Rails.logger.respond_to? :flush
         | 
| 50 | 
            +
                          rescue Exception => e
         | 
| 51 | 
            +
                            if defined?(::Flail)
         | 
| 52 | 
            +
                              Flail::Exception.notify(e)
         | 
| 53 | 
            +
                            else
         | 
| 54 | 
            +
                              Rails.logger.error e.inspect
         | 
| 55 | 
            +
                            end
         | 
| 56 | 
            +
                          end
         | 
| 49 57 | 
             
                        end
         | 
| 50 58 | 
             
                      end
         | 
| 51 59 | 
             
                      alias_method_chain :call, :remnant_discovery
         | 
    
        data/lib/remnant/version.rb
    CHANGED
    
    
    
        data/spec/base_spec.rb
    CHANGED
    
    | @@ -1,23 +1,22 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 | 
            -
            describe  | 
| 3 | 
            +
            describe Remnant do
         | 
| 4 4 |  | 
| 5 5 | 
             
              context "#configuration" do
         | 
| 6 6 | 
             
                it "should return the same object for multiple calls" do
         | 
| 7 | 
            -
                   | 
| 7 | 
            +
                  Remnant.configuration.should == Remnant.configuration
         | 
| 8 8 | 
             
                end
         | 
| 9 9 | 
             
              end
         | 
| 10 10 |  | 
| 11 11 | 
             
              context "#configure" do
         | 
| 12 12 | 
             
                it "should fail without a block" do
         | 
| 13 | 
            -
                  lambda {  | 
| 13 | 
            +
                  lambda { Remnant.configure }.should raise_error
         | 
| 14 14 | 
             
                end
         | 
| 15 15 |  | 
| 16 16 | 
             
                it "should instance_eval the block onto configuration" do
         | 
| 17 17 | 
             
                  block = Proc.new { handle {|payload| } }
         | 
| 18 | 
            -
                  mock( | 
| 19 | 
            -
                   | 
| 18 | 
            +
                  mock(Remnant).configuration.stub!.instance_eval(&block)
         | 
| 19 | 
            +
                  Remnant.configure(&block)
         | 
| 20 20 | 
             
                end
         | 
| 21 21 | 
             
              end
         | 
| 22 22 | 
             
            end
         | 
| 23 | 
            -
             | 
| @@ -0,0 +1,64 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Remnant::Discover do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              before do
         | 
| 6 | 
            +
                Remnant::Discover.results.clear
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              context "#measure" do
         | 
| 10 | 
            +
                it "should preserve return" do
         | 
| 11 | 
            +
                  Remnant::Discover.measure('troll') { 'bridge'}.should == 'bridge'
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                it "should add to existing result" do
         | 
| 15 | 
            +
                  Remnant::Discover.results['fragment'].should == 0
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  Remnant::Discover.measure('fragment') { 'shattered' }
         | 
| 18 | 
            +
                  shattered_measurement = Remnant::Discover.results['fragment']
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  Remnant::Discover.measure('fragment') { 'intact' }
         | 
| 21 | 
            +
                  Remnant::Discover.results['fragment'].should > shattered_measurement
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                it "should add to existing nested results" do
         | 
| 25 | 
            +
                  Remnant::Discover.results['fragment'].should == 0
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  Remnant::Discover.measure('fragment') do
         | 
| 28 | 
            +
                    sleep 0.2
         | 
| 29 | 
            +
                    Remnant::Discover.measure('fragment') do
         | 
| 30 | 
            +
                      sleep 0.2
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  Remnant::Discover.results['fragment'].should < 410
         | 
| 35 | 
            +
                  Remnant::Discover.results['fragment'].should > 390
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              context "#find" do
         | 
| 40 | 
            +
                it "should be able to watch passing blocks" do
         | 
| 41 | 
            +
                  Remnant::Discover.find('yielding', Some::Klass, :yielder)
         | 
| 42 | 
            +
                  Some::Klass.new.yielder { 'techno'}.should == 'techno'
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                it "should be able to watch passing args" do
         | 
| 46 | 
            +
                  Remnant::Discover.find('echo', Some::Klass, :echo)
         | 
| 47 | 
            +
                  Some::Klass.new.echo(1, 1, 2, 3, 5).should == [1, 1, 2, 3, 5]
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                it "should be able to watch an instance method" do
         | 
| 51 | 
            +
                  Remnant::Discover.find('instance', Some::Klass, :foo)
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  Some::Klass.new.foo.should == 'foo'
         | 
| 54 | 
            +
                  Remnant::Discover.results['instance'].should_not == nil
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                it "should be able to watch a class method" do
         | 
| 58 | 
            +
                  Remnant::Discover.find('class_method', Some::Klass, :world, false)
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  Some::Klass.world.should == 'world'
         | 
| 61 | 
            +
                  Remnant::Discover.results['class_method'].should_not == nil
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -10,115 +10,11 @@ RSpec.configure do |config| | |
| 10 10 | 
             
            end
         | 
| 11 11 |  | 
| 12 12 | 
             
            require 'action_controller'
         | 
| 13 | 
            -
            require 'action_controller/test_process'
         | 
| 14 | 
            -
            require 'active_record'
         | 
| 15 13 | 
             
            require 'active_support'
         | 
| 16 | 
            -
            require 'rack'
         | 
| 17 | 
            -
            require 'sham_rack'
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            require 'flail'
         | 
| 20 | 
            -
            require 'flail/rails/controller_methods'
         | 
| 21 | 
            -
            require 'flail/rails/rescue_action'
         | 
| 22 14 |  | 
| 15 | 
            +
            require 'remnant'
         | 
| 23 16 |  | 
| 24 17 | 
             
            Dir["#{File.expand_path(File.dirname(__FILE__))}/support/*.rb"].map {|file| require(file)}
         | 
| 25 18 |  | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
              module ClassMethods
         | 
| 29 | 
            -
                def define_constant(name, value)
         | 
| 30 | 
            -
                  @defined_constants ||= []
         | 
| 31 | 
            -
                  Object.const_set(name, value)
         | 
| 32 | 
            -
                  @defined_constants << name
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                def build_controller_class(&definition)
         | 
| 36 | 
            -
                  Class.new(ActionController::Base).tap do |klass|
         | 
| 37 | 
            -
                    klass.__send__(:include, Flail::Rails::ControllerMethods)
         | 
| 38 | 
            -
                    klass.__send__(:include, Flail::Rails::RescueAction)
         | 
| 39 | 
            -
                    klass.class_eval(&definition) if definition
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                    klass.class_eval do
         | 
| 42 | 
            -
                      def rescue_action_in_public_without_flail(*args)
         | 
| 43 | 
            -
                      end
         | 
| 44 | 
            -
                    end
         | 
| 45 | 
            -
                    define_constant('FlailTestController', klass)
         | 
| 46 | 
            -
                  end
         | 
| 47 | 
            -
                end
         | 
| 48 | 
            -
             | 
| 49 | 
            -
                def process_action(options = {}, &action)
         | 
| 50 | 
            -
                  options[:request] ||= ActionController::TestRequest.new
         | 
| 51 | 
            -
                  options[:response] ||= ActionController::TestResponse.new
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                  klass = build_controller_class do
         | 
| 54 | 
            -
                    cattr_accessor :local
         | 
| 55 | 
            -
                    define_method(:index, &action)
         | 
| 56 | 
            -
             | 
| 57 | 
            -
                    def current_user
         | 
| 58 | 
            -
                      @current_user
         | 
| 59 | 
            -
                    end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                    def local_request?
         | 
| 62 | 
            -
                      local
         | 
| 63 | 
            -
                    end
         | 
| 64 | 
            -
                  end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                  if options[:user_agent]
         | 
| 67 | 
            -
                    if options[:request].respond_to?(:user_agent=)
         | 
| 68 | 
            -
                      options[:request].user_agent = options[:user_agent]
         | 
| 69 | 
            -
                    else
         | 
| 70 | 
            -
                      options[:request].env["HTTP_USER_AGENT"] = options[:user_agent]
         | 
| 71 | 
            -
                    end
         | 
| 72 | 
            -
                  end
         | 
| 73 | 
            -
             | 
| 74 | 
            -
                  klass.consider_all_requests_local = options[:all_local]
         | 
| 75 | 
            -
                  klass.local = options[:local]
         | 
| 76 | 
            -
             | 
| 77 | 
            -
                  controller = klass.new
         | 
| 78 | 
            -
             | 
| 79 | 
            -
                  if options[:user]
         | 
| 80 | 
            -
                    controller.instance_variable_set(:@current_user, options[:user])
         | 
| 81 | 
            -
                  end
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                  options[:request].query_parameters = options[:request].query_parameters.merge(options[:params] || {})
         | 
| 84 | 
            -
                  options[:request].session = ActionController::TestSession.new(options[:session] || {})
         | 
| 85 | 
            -
                  options[:request].env['REQUEST_URI'] = options[:request].request_uri
         | 
| 86 | 
            -
             | 
| 87 | 
            -
                  controller.process(options[:request], options[:response])
         | 
| 88 | 
            -
                  controller
         | 
| 89 | 
            -
                end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                def process_action_with_error(options = {})
         | 
| 92 | 
            -
                  process_action(options) do
         | 
| 93 | 
            -
                    raise "Hello"
         | 
| 94 | 
            -
                  end
         | 
| 95 | 
            -
                end
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                def setup
         | 
| 98 | 
            -
                  Flail.configure do
         | 
| 99 | 
            -
                    handle do |payload|
         | 
| 100 | 
            -
                      FlailArmory.payload = ActiveSupport::JSON.decode(payload)
         | 
| 101 | 
            -
                    end
         | 
| 102 | 
            -
                  end
         | 
| 103 | 
            -
                  define_constant('RAILS_ROOT', '/path/to/rails/root')
         | 
| 104 | 
            -
                end
         | 
| 105 | 
            -
             | 
| 106 | 
            -
                def payload=(value)
         | 
| 107 | 
            -
                  @payload = value
         | 
| 108 | 
            -
                end
         | 
| 109 | 
            -
             | 
| 110 | 
            -
                def payload
         | 
| 111 | 
            -
                  @payload
         | 
| 112 | 
            -
                end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                def raid
         | 
| 115 | 
            -
                  @defined_constants.each do |constant|
         | 
| 116 | 
            -
                    Object.__send__(:remove_const, constant)
         | 
| 117 | 
            -
                  end
         | 
| 118 | 
            -
             | 
| 119 | 
            -
                  @payload = nil
         | 
| 120 | 
            -
                  @defined_constants = []
         | 
| 121 | 
            -
                end
         | 
| 122 | 
            -
              end
         | 
| 123 | 
            -
              extend ClassMethods
         | 
| 124 | 
            -
            end
         | 
| 19 | 
            +
            # for dependency reloading
         | 
| 20 | 
            +
            ActiveSupport::Dependencies.autoload_paths << File.dirname(__FILE__) + '/app/'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: remnant
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-09- | 
| 12 | 
            +
            date: 2012-09-17 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: statsd-ruby
         | 
| @@ -131,6 +131,7 @@ executables: [] | |
| 131 131 | 
             
            extensions: []
         | 
| 132 132 | 
             
            extra_rdoc_files: []
         | 
| 133 133 | 
             
            files:
         | 
| 134 | 
            +
            - .rvmrc
         | 
| 134 135 | 
             
            - Gemfile
         | 
| 135 136 | 
             
            - Gemfile.lock
         | 
| 136 137 | 
             
            - LICENSE
         | 
| @@ -144,7 +145,10 @@ files: | |
| 144 145 | 
             
            - lib/remnant/railtie.rb
         | 
| 145 146 | 
             
            - lib/remnant/version.rb
         | 
| 146 147 | 
             
            - remnant.gemspec
         | 
| 148 | 
            +
            - spec/app/some/klass.rb
         | 
| 149 | 
            +
            - spec/app/some/module.rb
         | 
| 147 150 | 
             
            - spec/base_spec.rb
         | 
| 151 | 
            +
            - spec/discover_spec.rb
         | 
| 148 152 | 
             
            - spec/spec_helper.rb
         | 
| 149 153 | 
             
            - spec/support/rr.rb
         | 
| 150 154 | 
             
            homepage: https://github.com/asceth/remnant
         | 
| @@ -172,6 +176,9 @@ signing_key: | |
| 172 176 | 
             
            specification_version: 3
         | 
| 173 177 | 
             
            summary: Rails statistical discoverer
         | 
| 174 178 | 
             
            test_files:
         | 
| 179 | 
            +
            - spec/app/some/klass.rb
         | 
| 180 | 
            +
            - spec/app/some/module.rb
         | 
| 175 181 | 
             
            - spec/base_spec.rb
         | 
| 182 | 
            +
            - spec/discover_spec.rb
         | 
| 176 183 | 
             
            - spec/spec_helper.rb
         | 
| 177 184 | 
             
            - spec/support/rr.rb
         |