inferno 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2I3OGVjMDNiZWRkODgyMTAzYmQ1YjcxNTBkMGVjZjk4ZDkwNThmZg==
4
+ ODhlNDVmMTNmM2U0MzJmYzM0YTFjMzcxYmJmZWMwZjg5MmQ1ZDRkMg==
5
5
  data.tar.gz: !binary |-
6
- Njg0NzNmMDY1OTg0ZjY5YjEwM2MwZDk5YmY4N2JlZTlkYjY0M2M1NQ==
6
+ NDUzMTUwZGJlOTExNWM1MDlkMzBmMWI0MWNlYjZkYjEyNDU2OTA2OQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZjIwMWZmZGQ5MjA3MDlhNDhjNTY4YmYwZWQ4MDM4NzgyOGViZDJkZDk1NDM4
10
- YjdiNzk0NGEwY2NkNGFjZTliMzRmMDA4NjA3OWM3MDkzMGNlMGMyYmVhZjZm
11
- NjA4NDI5MWFiZjEzODM3MDM5OGVmYTA3NzEwYTcxMGYxYTdlOTk=
9
+ YTFjYzIxM2M5ZjVhNGIzZDFkYzQ0MzgwZDc2YmQ5MDRjMmIxM2E5MTUzOWY0
10
+ MmVjZWRjMWMxYzNiODQ4NjU4N2YzZmIwZGYwNzBhMGE1YWEyMGIxZWU0MzIz
11
+ OGRkMjAxMjJiOTU5M2RiOTM2Njg5N2M3OWJlZTYxMTQxMmQzY2I=
12
12
  data.tar.gz: !binary |-
13
- MTgyZTY5OTQxMjc2ZDBkOTFjMTQwMjQ1OTA2ZTBjY2Q0MmQ3Y2U1MTFiZGFl
14
- NDQxOGRkNjc4ZmJlODk0NThlYTE3YjU3NDc2YWQ1YmQ2YjU5ZjkyM2FlY2Iz
15
- YjY1OTQxYTg4OTQwMWNkMTgwNzBmOTRiMTllYjliMmQ0Y2M2MDE=
13
+ YTQ0OGVmMzMzNGM2ODhkM2FmNDM1YmQwMDEzNWExMzZiZGM1NTczNDc2Njdm
14
+ MDc4N2Y2YmYxZmY2ZTk5NzM3NzEyNTI4Njc4YjY5ZTM5OTJmOTRkZTZmN2I1
15
+ YTc2OWRmZjhjZDdjYWZiOThjODczNjQ2NGI5MGM0ODExNjVlNTU=
@@ -2,7 +2,8 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'inferno/version'
5
-
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new('spec')
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "inferno"
8
9
  spec.version = Inferno::VERSION
@@ -19,5 +20,6 @@ Gem::Specification.new do |spec|
19
20
 
20
21
  spec.add_development_dependency "bundler", "~> 1.5"
21
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
22
24
  spec.add_dependency "eventmachine"
23
25
  end
@@ -1,3 +1,3 @@
1
1
  module Inferno
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ class DummyContextObject
4
+ def initialize
5
+ @test_var = 1
6
+ end
7
+
8
+ def incr
9
+ @test_var += 1
10
+ end
11
+
12
+ def test_var
13
+ @test_var
14
+ end
15
+ end
16
+
17
+ describe Inferno::Event do
18
+ it "should allow add actions and run it in proper context" do
19
+ dummy = DummyContextObject.new
20
+ notifications = Inferno::Event.new
21
+ notifications.on(:test, dummy) { @test_var = 2 }
22
+ notifications.count(:test).should eq(1)
23
+ notifications.trigger(:test)
24
+
25
+ dummy.test_var.should eq(2)
26
+ end
27
+
28
+ it "should trigger event only once" do
29
+ dummy = DummyContextObject.new
30
+ notifications = Inferno::Event.new
31
+ notifications.once(:test, dummy) { dummy.incr }
32
+ notifications.count(:test).should eq(2)
33
+ dummy.test_var.should eq(1)
34
+ 10.times { notifications.trigger(:test) }
35
+
36
+ dummy.test_var.should eq(2)
37
+ end
38
+
39
+ it "should remove events" do
40
+ dummy = DummyContextObject.new
41
+ notifications = Inferno::Event.new
42
+
43
+ notifications.on(:test, dummy) { @test_var = 2 }
44
+ notifications.count(:test).should eq(1)
45
+ notifications.off(:test, dummy)
46
+ notifications.count(:test).should eq(0)
47
+
48
+ notifications.on(:test, dummy) {}
49
+ notifications.on(:test, self) {}
50
+
51
+ notifications.count(:test).should eq(2)
52
+
53
+ notifications.off(:test, dummy)
54
+ notifications.count(:test).should eq(1)
55
+
56
+ notifications.off(:test, self)
57
+ notifications.count(:test).should eq(0)
58
+ end
59
+
60
+ it "should allow transfer payloads" do
61
+ notifications = Inferno::Event.new
62
+
63
+ notifications.on(:test, self) do |payload|
64
+ payload.should_not be_nil
65
+ payload[:test].should eq(1)
66
+ end
67
+ notifications.trigger(:test, { test: 1 })
68
+ end
69
+
70
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'inferno'
6
+ require 'rspec'
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inferno
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkadiusz Buras
@@ -40,6 +40,22 @@ dependencies:
40
40
  name: rake
41
41
  type: :development
42
42
  prerelease: false
43
+ - !ruby/object:Gem::Dependency
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: !binary |-
49
+ MA==
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: !binary |-
55
+ MA==
56
+ name: rspec
57
+ type: :development
58
+ prerelease: false
43
59
  - !ruby/object:Gem::Dependency
44
60
  requirement: !ruby/object:Gem::Requirement
45
61
  requirements:
@@ -71,6 +87,8 @@ files:
71
87
  - inferno.gemspec
72
88
  - lib/inferno.rb
73
89
  - lib/inferno/version.rb
90
+ - spec/event_spec.rb
91
+ - spec/spec_helper.rb
74
92
  homepage: http://macbury.pl
75
93
  licenses:
76
94
  - MIT
@@ -98,4 +116,6 @@ signing_key:
98
116
  specification_version: 4
99
117
  summary: Gem gives object the ability to bind and trigger custom named events. Events
100
118
  do not have to be declared before they are bound, and may take passed arguments.
101
- test_files: []
119
+ test_files:
120
+ - spec/event_spec.rb
121
+ - spec/spec_helper.rb