mtrack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
1
+ require "spec_helper"
2
+
3
+ describe MTrack::State::Group do
4
+ context "newly instantiated" do
5
+ it "is initialized empty" do
6
+ expect(subject.tracked).to be_empty
7
+ end
8
+ end
9
+
10
+ context "already in use" do
11
+ let(:sample_tracked) { [:trk_1, :trk_2, :trk_3] }
12
+
13
+ subject do
14
+ described_class.new.tap do |o|
15
+ o.merge_tracked sample_tracked
16
+ end
17
+ end
18
+
19
+ it "is not empty" do
20
+ expect(subject.tracked).to match_array(sample_tracked)
21
+ end
22
+
23
+ it "does not modify internal state through attribute readers" do
24
+ expect(subject.tracked.add(:v)).to match_array(sample_tracked + [:v])
25
+ expect(subject.tracked).to match_array(sample_tracked)
26
+ end
27
+
28
+ it "deletes tracked values" do
29
+ expect(subject.delete_tracked(:trk_2)).to be(:trk_2)
30
+ expect(subject.tracked).to match_array(sample_tracked - [:trk_2])
31
+ end
32
+
33
+ it "merges tracked values" do
34
+ expect(subject.merge_tracked([:x, :y, :z])).to match_array([:x, :y, :z])
35
+ expect(subject.tracked).to match_array(sample_tracked + [:x, :y, :z])
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,135 @@
1
+ require "spec_helper"
2
+
3
+ describe MTrack::State do
4
+ let(:sample_group) do
5
+ { :con_1 => { :tracked => [:trk_1, :trk_2] },
6
+ :con_2 => { :tracked => [:trk_2, :trk_3] }
7
+ }
8
+ end
9
+ let(:sample_group_2) do
10
+ { :con_2 => { :tracked => [:trk_3, :trk_4] },
11
+ :con_3 => { :tracked => [:trk_4, :trk_5] }
12
+ }
13
+ end
14
+
15
+ let(:sample_undefined) { [:und_1, :und_2, :und_3] }
16
+
17
+ let(:sample_state) do
18
+ described_class.new.tap do |o|
19
+ sample_group.keys.each do |key|
20
+ o[key].merge_tracked sample_group[key][:tracked]
21
+ end
22
+ sample_undefined.each {|v| o.add_undefined v }
23
+ end
24
+ end
25
+ let(:sample_state_2) do
26
+ described_class.new.tap do |o|
27
+ sample_group_2.keys.each do |key|
28
+ o[key].merge_tracked sample_group_2[key][:tracked]
29
+ end
30
+ end
31
+ end
32
+
33
+ it "adds a new group when using the `[]` operator" do
34
+ expect(new_group = subject[:new_group]).to be_a(MTrack::State::Group)
35
+ expect(subject[:new_group]).to be(new_group)
36
+ end
37
+
38
+ it "adds super states" do
39
+ expect(subject.add_super_state(sample_state)).to be(sample_state)
40
+ expect(subject.add_super_state(sample_state_2)).to be(sample_state_2)
41
+ end
42
+
43
+ context "newly instantiated" do
44
+ context "without super state" do
45
+ subject { described_class.new }
46
+
47
+ it "does not have tracked methods" do
48
+ expect(subject.tracked).to be_empty
49
+ end
50
+ end
51
+
52
+ context "with super state" do
53
+ subject { described_class.new sample_state }
54
+
55
+ it "has super state's tracked methods" do
56
+ expect(sample_state.tracked(:con_1)).to match_array(sample_group[:con_1][:tracked])
57
+ expect(sample_state.tracked(:con_2)).to match_array(sample_group[:con_2][:tracked])
58
+ expect(subject.tracked(:con_1)).to match_array(sample_state.tracked(:con_1))
59
+ expect(subject.tracked(:con_2)).to match_array(sample_state.tracked(:con_2))
60
+ end
61
+ end
62
+
63
+ context "with multiple super states" do
64
+ subject { described_class.new(sample_state).tap {|s| s.add_super_state sample_state_2 } }
65
+
66
+ it "merges tracked methods from all super states" do
67
+ expect(subject.tracked(:con_1)).to match_array(sample_group[:con_1][:tracked])
68
+ expect(subject.tracked(:con_2)).to match_array(sample_group[:con_2][:tracked] | sample_group_2[:con_2][:tracked])
69
+ expect(subject.tracked(:con_3)).to match_array(sample_group_2[:con_3][:tracked])
70
+ end
71
+
72
+ it "returns tracked methods that are not undefined" do
73
+ subject.add_undefined :trk_3
74
+ expect(subject.tracked(:con_2)).to match_array((sample_group[:con_2][:tracked] | sample_group_2[:con_2][:tracked]) - [:trk_3])
75
+
76
+ subject.delete_undefined :trk_3
77
+ expect(subject.tracked(:con_2)).to match_array((sample_group[:con_2][:tracked] | sample_group_2[:con_2][:tracked]))
78
+ end
79
+ end
80
+ end
81
+
82
+ context "already in use" do
83
+ subject { sample_state }
84
+
85
+ it "is not empty" do
86
+ expect(subject[:con_1].tracked).to match_array(sample_group[:con_1][:tracked])
87
+ expect(subject[:con_2].tracked).to match_array(sample_group[:con_2][:tracked])
88
+ end
89
+
90
+ it "adds undefined methods" do
91
+ expect(subject.add_undefined(:v)).to eq(:v)
92
+ end
93
+
94
+ it "deletes tracked methods" do
95
+ expect(subject.delete_tracked(:trk_2)).to eq(:trk_2)
96
+ expect(subject[:con_1].tracked).to match_array(sample_group[:con_1][:tracked] - [:trk_2])
97
+ expect(subject[:con_2].tracked).to match_array(sample_group[:con_2][:tracked] - [:trk_2])
98
+ end
99
+
100
+ it "deletes undefined methods" do
101
+ expect(subject.delete_undefined(:und_2)).to eq(:und_2)
102
+ end
103
+
104
+ it "returns tracked methods that are not undefined" do
105
+ expect(subject.tracked(:con_1)).to match_array(sample_group[:con_1][:tracked])
106
+ expect(subject.tracked(:con_2)).to match_array(sample_group[:con_2][:tracked])
107
+
108
+ subject.add_undefined :trk_2
109
+ expect(subject.tracked(:con_1)).to match_array(sample_group[:con_1][:tracked] - [:trk_2])
110
+ expect(subject.tracked(:con_2)).to match_array(sample_group[:con_2][:tracked] - [:trk_2])
111
+
112
+ subject.delete_undefined :trk_2
113
+ expect(subject.tracked(:con_1)).to match_array(sample_group[:con_1][:tracked])
114
+ expect(subject.tracked(:con_2)).to match_array(sample_group[:con_2][:tracked])
115
+ end
116
+
117
+ context "with super state" do
118
+ subject { sample_state.tap {|s| s.add_super_state sample_state_2 } }
119
+
120
+ it "merges tracked methods from current and super states" do
121
+ expect(subject.tracked(:con_1)).to match_array(sample_group[:con_1][:tracked])
122
+ expect(subject.tracked(:con_2)).to match_array(sample_group[:con_2][:tracked] | sample_group_2[:con_2][:tracked])
123
+ expect(subject.tracked(:con_3)).to match_array(sample_group_2[:con_3][:tracked])
124
+ end
125
+
126
+ it "returns tracked methods that are not undefined" do
127
+ subject.add_undefined :trk_3
128
+ expect(subject.tracked(:con_2)).to match_array((sample_group[:con_2][:tracked] | sample_group_2[:con_2][:tracked]) - [:trk_3])
129
+
130
+ subject.delete_undefined :trk_3
131
+ expect(subject.tracked(:con_2)).to match_array((sample_group[:con_2][:tracked] | sample_group_2[:con_2][:tracked]))
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe MTrack::VERSION do
4
+ it { should_not be_nil }
5
+ end
@@ -0,0 +1,21 @@
1
+ unless ENV["COVERAGE"].nil?
2
+ require "codeclimate-test-reporter"
3
+ SimpleCov.start do
4
+ formatter SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ CodeClimate::TestReporter::Formatter
7
+ ]
8
+ add_filter "/spec/"
9
+ end
10
+ end
11
+
12
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
13
+ require "mtrack"
14
+
15
+ RSpec.configure do |config|
16
+ config.color = true
17
+ config.order = :rand
18
+ config.expect_with :rspec do |c|
19
+ c.syntax = :expect
20
+ end
21
+ end
data/tasks/console.rb ADDED
@@ -0,0 +1,13 @@
1
+ desc "Open a console with the #{Bundler::GemHelper.gemspec.name} gem loaded"
2
+ task :console do
3
+ require Bundler::GemHelper.gemspec.name
4
+
5
+ if RUBY_VERSION >= "1.9"
6
+ require "pry"
7
+ Pry.start
8
+ else
9
+ require "irb"
10
+ ARGV.clear
11
+ IRB.start
12
+ end
13
+ end
data/tasks/coverage.rb ADDED
@@ -0,0 +1,9 @@
1
+ desc "Run tests and generate coverage report"
2
+ task :coverage do
3
+ if RUBY_VERSION >= "1.9"
4
+ ENV["COVERAGE"] = "true"
5
+ else
6
+ warn "Ruby version 1.9+ is needed in order to generate coverage report."
7
+ end
8
+ Rake::Task[:spec].invoke
9
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mtrack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gabriel de Oliveira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codeclimate-test-reporter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: MTrack extends the functionality of modules and classes and enables them
98
+ to define public methods within groups. These methods can then be queried back even
99
+ through a hierarchy of inclusion and/or inheritance.
100
+ email:
101
+ - deoliveira.gab@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".ruby-version"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Guardfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - lib/mtrack.rb
115
+ - lib/mtrack/core.rb
116
+ - lib/mtrack/module_mixin.rb
117
+ - lib/mtrack/state.rb
118
+ - lib/mtrack/state/group.rb
119
+ - lib/mtrack/version.rb
120
+ - mtrack.gemspec
121
+ - spec/lib/mtrack/core_spec.rb
122
+ - spec/lib/mtrack/state/group_spec.rb
123
+ - spec/lib/mtrack/state_spec.rb
124
+ - spec/lib/mtrack/version_spec.rb
125
+ - spec/spec_helper.rb
126
+ - tasks/console.rb
127
+ - tasks/coverage.rb
128
+ homepage: https://github.com/gdeoliveira/mtrack
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.1
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Group and track methods on classes and modules.
152
+ test_files:
153
+ - spec/lib/mtrack/core_spec.rb
154
+ - spec/lib/mtrack/state/group_spec.rb
155
+ - spec/lib/mtrack/state_spec.rb
156
+ - spec/lib/mtrack/version_spec.rb
157
+ - spec/spec_helper.rb