Sha256: e896e0fffb39f0c5720b50e67e87ae1a4c6ffeed0044c4abb5d3b659c7784430

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

describe Remnant::Discover do

  before do
    Remnant::Discover.results.clear
  end

  context "#measure" do
    it "should preserve return" do
      Remnant::Discover.measure('troll') { 'bridge'}.should == 'bridge'
    end

    it "should add to existing result" do
      Remnant::Discover.results['fragment'].should == 0

      Remnant::Discover.measure('fragment') { 'shattered' }
      shattered_measurement = Remnant::Discover.results['fragment']

      Remnant::Discover.measure('fragment') { 'intact' }
      Remnant::Discover.results['fragment'].should > shattered_measurement
    end

    it "should add to existing nested results" do
      Remnant::Discover.results['fragment'].should == 0

      Remnant::Discover.measure('fragment') do
        sleep 0.2
        Remnant::Discover.measure('fragment') do
          sleep 0.2
        end
      end

      Remnant::Discover.results['fragment'].should < 410
      Remnant::Discover.results['fragment'].should > 390
    end
  end

  context "#find" do
    it "should be able to watch passing blocks" do
      Remnant::Discover.find('yielding', Some::Klass, :yielder)
      Some::Klass.new.yielder { 'techno'}.should == 'techno'
    end

    it "should be able to watch passing args" do
      Remnant::Discover.find('echo', Some::Klass, :echo)
      Some::Klass.new.echo(1, 1, 2, 3, 5).should == [1, 1, 2, 3, 5]
    end

    it "should be able to watch an instance method" do
      Remnant::Discover.find('instance', Some::Klass, :foo)

      Some::Klass.new.foo.should == 'foo'
      Remnant::Discover.results['instance'].should_not == nil
    end

    it "should be able to watch a class method" do
      Remnant::Discover.find('class_method', Some::Klass, :world, false)

      Some::Klass.world.should == 'world'
      Remnant::Discover.results['class_method'].should_not == nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remnant-0.2.0 spec/discover_spec.rb