fix 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f19dfa7434852c7c1d926d17e866c7c2deca0409
4
- data.tar.gz: c1a32d2eaec17157c061936e473231f5da7e8090
3
+ metadata.gz: 31c51a42cf1817594ac8acded17fe569bca8fbc5
4
+ data.tar.gz: 9e4fd8700a2c41a7420ed048b520fb802e485c34
5
5
  SHA512:
6
- metadata.gz: 94436f147c902c8e170e3c7897b158bff5bab6c49af1365678559621833e8e548f2931b9e0c798a6d056a649c35145012eca97afc2f4bdcbf7498ca29b7a777d
7
- data.tar.gz: 25921c2ae0b3a8904c5d5d74d36df83adc14f26b7ee8873c94019be00f79bc4d6a607976724b7557ec74897c1c2ea5d8cac9ef39fb259491b477d94c39ecb598
6
+ metadata.gz: d95d05cc3ba74fb316d61df20fd2519b52c3a3b52f3c8025d9cfe96c12fd05b6ba120118ab1d9ef09becb878c09eb703b6d69bfca3a3d5d5650d013027dfd53c
7
+ data.tar.gz: d1ee4975f7eac819051d464a83dfee7b617bf9cdd8bd6f26b68fb5210d0a7d4f34e16692e1f46402e4c98fc30181b8ec121986a82ddaed28abf1402c703936f3
Binary file
data.tar.gz.sig CHANGED
@@ -1,4 +1 @@
1
- ����=�7M�z���wr'��hقq�/�:�i}��7�������XK*i|膦���
2
- F; ߤhA�j������2f���sX4�`�4ժ׌,p8�E4l��SO���d�aټ"e�u���¿�%�����P���3�e
3
- ��ـ��D1ܴ&�ί?̮$[f�U�E��G m2Ùk�=�9E���Qy�&��I
4
- ����4������~����
1
+ F!��c3VaM�[k�X�;{�|��m�����"q�e��Q�Gݐ���iJ㹡��Bd�s�9m�P��@UOГc�����C7�^�A`��@y�T��A��(�"#�j�$�X��"���Н#~Ĉ��,4&v�Q�H֋ܔ|��,Q-]�α%��Z��z@��BCG ������-��0���[;RxAV�;�ǦI��Xj�^�a-�#�UH��2�$'�q$�T��r�hƄ���t�!x[��;1�%x�8G��
data/README.md CHANGED
@@ -76,47 +76,38 @@ class Duck
76
76
  end
77
77
 
78
78
  @bird = Duck.new
79
- ```
80
-
81
- > When I see a `#<Duck:0x007f96b285d6d0>` that ...
82
79
 
83
- ```ruby
84
80
  require 'fix'
85
81
 
86
- @duck_spec = Fix::Spec.new :duck do
87
- on :swims do
88
- it { SHALL eql: "Swoosh..." }
89
- it { MAY capture_stdout: " ...\n" }
90
- end
82
+ extend Fix::DSL
91
83
 
92
- on :quacks do
93
- it { SHOULD capture_stdout: "Quaaaaaack!\n" }
94
- end
84
+ subject @bird
95
85
 
96
- on :speaks do
97
- it { MUST raise_exception: NoMethodError }
98
- end
86
+ on :swims do
87
+ it { SHALL eql: "Swoosh..." }
88
+ it { MAY capture_stdout: " ...\n" }
89
+ end
99
90
 
100
- on :sings do
101
- it { MAY eql: "♪... ♫..." }
102
- end
91
+ on :quacks do
92
+ it { SHOULD capture_stdout: "Quaaaaaack!\n" }
93
+ end
94
+
95
+ on :speaks do
96
+ it { MUST raise_exception: NoMethodError }
103
97
  end
104
98
 
105
- case @duck_spec.valid? @bird
106
- when true then puts "I call that #{@bird} a duck."
107
- else warn 'WAT?'
99
+ on :sings do
100
+ it { MAY eql: "♪... ♫..." }
108
101
  end
109
102
  ```
110
103
 
111
104
  ```bash
112
- ruby test.rb
113
- # Run options: --seed 241686681690348892099960370893524466040
114
- # .....
115
- # Finished in 0.001033 seconds.
116
- # 5 tests, 0 failures, 0 errors
105
+ ruby duck_spec.rb
117
106
  ```
118
107
 
119
- > I call that `#<Duck:0x007f96b285d6d0>` a duck.
108
+ .....
109
+ Finished in 0.001033 seconds.
110
+ 5 tests, 0 failures, 0 errors
120
111
 
121
112
  ## Contributing
122
113
 
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -2,7 +2,6 @@
2
2
 
3
3
  ```bash
4
4
  $ ./test.rb
5
- Run options: --seed 122743552393459455928023127107893880649
6
5
  ......
7
6
  Finished in 0.001181 seconds.
8
7
  6 tests, 0 failures, 0 errors
@@ -1,6 +1,36 @@
1
1
  #!/usr/bin/env ruby -w
2
2
 
3
3
  require_relative 'app'
4
- require_relative 'spec'
4
+ require 'fix'
5
5
 
6
- @spec.test @app
6
+ extend Fix::DSL
7
+
8
+ subject @app
9
+
10
+ let(:word) { "Quaaa" }
11
+
12
+ on :swims do
13
+ it { MUST capture_stderr: " ...\n" }
14
+ end
15
+
16
+ on :quacks do
17
+ let(:quaaaaaack) { word + "aaack!\n" }
18
+
19
+ it { SHOULD capture_stdout: quaaaaaack }
20
+ end
21
+
22
+ its(:speaks) { MUST raise_exception: NoMethodError }
23
+
24
+ on :sings do
25
+ it { MAY eql: "♪... ♫..." }
26
+ end
27
+
28
+ on :walks do
29
+ let(:walks) { "#{word}... Klop klop!" }
30
+
31
+ it { MUST eql: walks }
32
+
33
+ on :split, '... ' do
34
+ its(:last) { MUST eql: "Klop klop!" }
35
+ end
36
+ end
data/lib/fix.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative File.join 'fix', 'spec'
1
+ require_relative File.join 'fix', 'dsl'
2
2
  require_relative File.join 'fix', 'version'
3
3
 
4
4
  # Namespace for the Fix framework.
@@ -1,8 +1,11 @@
1
- require 'set'
2
1
  require 'singleton'
3
2
 
4
3
  module Fix
5
- class ExpectationSet < Set
4
+ class DB < Hash
6
5
  include Singleton
6
+
7
+ def random
8
+ Random.new
9
+ end
7
10
  end
8
11
  end
@@ -1,10 +1,17 @@
1
1
  require_relative File.join 'helper', 'its_helper'
2
2
  require_relative File.join 'helper', 'on_helper'
3
+ require_relative 'test'
3
4
 
4
5
  module Fix
5
6
  module DSL
6
7
  include Helper::ItsHelper
7
8
  include Helper::LetWriterHelper
8
9
  include Helper::OnHelper
10
+
11
+ def subject object
12
+ @object = object
13
+ end
14
+
15
+ at_exit { Test.new }
9
16
  end
10
17
  end
@@ -1,18 +1,27 @@
1
- require_relative File.join 'expectation_set'
1
+ require 'set'
2
2
  require 'spectus'
3
+ require_relative 'db'
3
4
 
4
5
  module Fix
5
6
  class Expectation
6
7
  include Spectus::DSL
7
8
 
8
- def initialize positive, definition, *args
9
+ attr_reader :priority
10
+
11
+ def initialize object, positive, definition, *args
9
12
  @positive = positive
10
13
  @matcher, @expected = definition.to_a.flatten 1
11
14
  @args = args
15
+ @priority = DB.instance.random.rand
12
16
 
13
17
  freeze
14
18
 
15
- ExpectationSet.instance.add self
19
+ DB.instance.update(object => SortedSet[]) unless DB.instance.key? object
20
+ DB.instance.fetch(object).add self
21
+ end
22
+
23
+ def <=> other
24
+ self.priority <=> other.priority
16
25
  end
17
26
 
18
27
  private
@@ -1,5 +1,5 @@
1
- require_relative File.join 'expectation'
2
- require_relative File.join 'subject'
1
+ require_relative 'expectation'
2
+ require_relative 'subject'
3
3
 
4
4
  module Fix
5
5
  class ExpectationHigh < Expectation
@@ -1,4 +1,4 @@
1
- require_relative File.join 'expectation_medium'
1
+ require_relative 'expectation_medium'
2
2
 
3
3
  module Fix
4
4
  class ExpectationLow < ExpectationMedium
@@ -1,4 +1,4 @@
1
- require_relative File.join 'expectation_high'
1
+ require_relative 'expectation_high'
2
2
 
3
3
  module Fix
4
4
  class ExpectationMedium < ExpectationHigh
@@ -1,12 +1,12 @@
1
1
  module Fix
2
2
  module Helper
3
- module ItsHelper
4
- def its attribute, *args, &block
5
- i = Its.new @defs, *(@args + [[attribute] + args])
3
+ module ItHelper
4
+ def it &block
5
+ i = It.new @object, @defs, *@args
6
6
  i.instance_eval(&block)
7
7
  end
8
8
  end
9
9
  end
10
10
  end
11
11
 
12
- require_relative File.join '..', 'its'
12
+ require_relative File.join '..', 'it'
@@ -1,12 +1,21 @@
1
1
  module Fix
2
2
  module Helper
3
- module ItHelper
4
- def it &block
5
- i = It.new @defs, *@args
3
+ module ItsHelper
4
+ def its attribute, *args, &block
5
+ unless instance_variable_defined? :@object
6
+ raise MissingSubjectError, "Incomplete specifications. " \
7
+ "Please specify a `subject` on the top."
8
+ end
9
+
10
+ @defs = {} unless instance_variable_defined? :@defs
11
+ @args = [] unless instance_variable_defined? :@args
12
+
13
+ i = Its.new @object, @defs, *(@args + [[attribute] + args])
6
14
  i.instance_eval(&block)
7
15
  end
8
16
  end
9
17
  end
10
18
  end
11
19
 
12
- require_relative File.join '..', 'it'
20
+ require_relative File.join '..', 'its'
21
+ require_relative File.join '..', 'missing_subject_error'
@@ -1,5 +1,5 @@
1
- require_relative File.join 'let_reader_helper'
2
- require_relative File.join 'let_writer_helper'
1
+ require_relative 'let_reader_helper'
2
+ require_relative 'let_writer_helper'
3
3
 
4
4
  module Fix
5
5
  module Helper
@@ -2,7 +2,7 @@ module Fix
2
2
  module Helper
3
3
  module LetReaderHelper
4
4
  def method_missing name, *args, &block
5
- @defs.has_key?(name) ? @defs.fetch(name).call : super
5
+ @defs.key?(name) ? @defs.fetch(name).call : super
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,9 @@ module Fix
2
2
  module Helper
3
3
  module LetWriterHelper
4
4
  def let name, &block
5
- if @defs.has_key? name
5
+ @defs = {} unless instance_variable_defined? :@defs
6
+
7
+ if @defs.key? name
6
8
  raise IndexError, 'the given key is already present.'
7
9
  else
8
10
  @defs.update name => block
@@ -2,11 +2,20 @@ module Fix
2
2
  module Helper
3
3
  module OnHelper
4
4
  def on attribute, *args, &block
5
- i = On.new @defs, *(@args + [[attribute] + args])
5
+ unless instance_variable_defined? :@object
6
+ raise MissingSubjectError, "Incomplete specifications. " \
7
+ "Please specify a `subject` on the top."
8
+ end
9
+
10
+ @defs = {} unless instance_variable_defined? :@defs
11
+ @args = [] unless instance_variable_defined? :@args
12
+
13
+ i = On.new @object, @defs, *(@args + [[attribute] + args])
6
14
  i.instance_eval(&block)
7
15
  end
8
16
  end
9
17
  end
10
18
  end
11
19
 
20
+ require_relative File.join '..', 'missing_subject_error'
12
21
  require_relative File.join '..', 'on'
@@ -1,4 +1,4 @@
1
- require_relative File.join 'let_reader_helper'
1
+ require_relative 'let_reader_helper'
2
2
 
3
3
  module Fix
4
4
  module Helper
@@ -6,32 +6,32 @@ module Fix
6
6
  include Helper::LetReaderHelper
7
7
 
8
8
  def MUST definition
9
- ExpectationHigh.new true, definition, *@args
9
+ ExpectationHigh.new @object, true, definition, *@args
10
10
  end
11
11
 
12
12
  alias_method :is_REQUIRED_to, :MUST
13
13
  alias_method :SHALL, :MUST
14
14
 
15
15
  def MUST_NOT definition
16
- ExpectationHigh.new false, definition, *@args
16
+ ExpectationHigh.new @object, false, definition, *@args
17
17
  end
18
18
 
19
19
  alias_method :SHALL_NOT, :MUST_NOT
20
20
 
21
21
  def SHOULD definition
22
- ExpectationMedium.new true, definition, *@args
22
+ ExpectationMedium.new @object, true, definition, *@args
23
23
  end
24
24
 
25
25
  alias_method :is_RECOMMENDED_to, :SHOULD
26
26
 
27
27
  def SHOULD_NOT definition
28
- ExpectationMedium.new false, definition, *@args
28
+ ExpectationMedium.new @object, false, definition, *@args
29
29
  end
30
30
 
31
31
  alias_method :is_NOT_RECOMMENDED_to, :SHOULD_NOT
32
32
 
33
33
  def MAY definition
34
- ExpectationLow.new true, definition, *@args
34
+ ExpectationLow.new @object, true, definition, *@args
35
35
  end
36
36
 
37
37
  alias_method :is_OPTIONAL_to, :MAY
@@ -4,9 +4,10 @@ module Fix
4
4
  class It
5
5
  include Helper::RequirementHelper
6
6
 
7
- def initialize defs, *args
8
- @defs = defs
9
- @args = args
7
+ def initialize object, defs, *args
8
+ @object = object
9
+ @defs = defs
10
+ @args = args
10
11
 
11
12
  freeze
12
13
  end
@@ -4,9 +4,10 @@ module Fix
4
4
  class Its
5
5
  include Helper::RequirementHelper
6
6
 
7
- def initialize defs, *args
8
- @defs = defs
9
- @args = args
7
+ def initialize object, defs, *args
8
+ @object = object
9
+ @defs = defs
10
+ @args = args
10
11
 
11
12
  freeze
12
13
  end
@@ -0,0 +1,7 @@
1
+ module Fix
2
+ # Missing subject error
3
+ #
4
+ # This is raised at the runtime when loading specs.
5
+ class MissingSubjectError < ::StandardError
6
+ end
7
+ end
@@ -10,9 +10,10 @@ module Fix
10
10
  include Helper::LetAccessorHelper
11
11
  include Helper::OnHelper
12
12
 
13
- def initialize defs, *args
14
- @defs = defs
15
- @args = args
13
+ def initialize object, defs, *args
14
+ @object = object
15
+ @defs = defs
16
+ @args = args
16
17
 
17
18
  freeze
18
19
  end
@@ -1,20 +1,18 @@
1
- require_relative File.join 'expectation_set'
1
+ require_relative 'db'
2
2
 
3
3
  module Fix
4
4
  class Test
5
5
  attr_reader :total_time
6
6
 
7
- def initialize front_object, seed: Random.new_seed, color: true, stdout: STDOUT, stderr: STDERR
7
+ def initialize color: true, stdout: STDOUT, stderr: STDERR
8
8
  @options = { color: color, stdout: stdout, stderr: stderr }
9
- @options.fetch(:stdout).puts about "Run options: --seed #{seed}"
10
-
11
- random = Random.new seed
12
- expectations = ExpectationSet.instance.to_a.shuffle(random: random)
13
9
 
14
10
  start_time = Time.now
15
- @results = expectations.map do |expectation|
16
- log expectation.evaluate front_object
17
- end
11
+ @results = DB.instance.map do |object, expectations|
12
+ expectations.map do |expectation|
13
+ log expectation.evaluate object
14
+ end
15
+ end.flatten 1
18
16
  @total_time = Time.now - start_time
19
17
 
20
18
  @options.fetch(:stdout).puts about "\nFinished in #{@total_time} seconds."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Wack
@@ -30,7 +30,7 @@ cert_chain:
30
30
  sQCgS9KCAyZ+aWNO1bUJcE3Bx1XXkMO3JEyVR1CoEcexg5Ci03/lAm7lL84DmlKR
31
31
  3I7UWtomapPFbzC0J/5jzQ==
32
32
  -----END CERTIFICATE-----
33
- date: 2014-09-25 00:00:00.000000000 Z
33
+ date: 2014-09-26 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: spectus
@@ -120,17 +120,16 @@ files:
120
120
  - example/duck/README.md
121
121
  - example/duck/app.rb
122
122
  - example/duck/lib.rb
123
- - example/duck/spec.rb
124
123
  - example/duck/test.rb
125
124
  - fix.gemspec
126
125
  - fix.pem
127
126
  - lib/fix.rb
127
+ - lib/fix/db.rb
128
128
  - lib/fix/dsl.rb
129
129
  - lib/fix/expectation.rb
130
130
  - lib/fix/expectation_high.rb
131
131
  - lib/fix/expectation_low.rb
132
132
  - lib/fix/expectation_medium.rb
133
- - lib/fix/expectation_set.rb
134
133
  - lib/fix/helper/it_helper.rb
135
134
  - lib/fix/helper/its_helper.rb
136
135
  - lib/fix/helper/let_accessor_helper.rb
@@ -140,8 +139,8 @@ files:
140
139
  - lib/fix/helper/requirement_helper.rb
141
140
  - lib/fix/it.rb
142
141
  - lib/fix/its.rb
142
+ - lib/fix/missing_subject_error.rb
143
143
  - lib/fix/on.rb
144
- - lib/fix/spec.rb
145
144
  - lib/fix/subject.rb
146
145
  - lib/fix/test.rb
147
146
  - lib/fix/version.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,31 +0,0 @@
1
- require 'fix'
2
-
3
- @spec = Fix::Spec.new :duck do
4
- let(:word) { "Quaaa" }
5
-
6
- on :swims do
7
- it { MUST capture_stderr: " ...\n" }
8
- end
9
-
10
- on :quacks do
11
- let(:quaaaaaack) { word + "aaack!\n" }
12
-
13
- it { SHOULD capture_stdout: quaaaaaack }
14
- end
15
-
16
- its(:speaks) { MUST raise_exception: NoMethodError }
17
-
18
- on :sings do
19
- it { MAY eql: "♪... ♫..." }
20
- end
21
-
22
- on :walks do
23
- let(:walks) { "#{word}... Klop klop!" }
24
-
25
- it { MUST eql: walks }
26
-
27
- on :split, '... ' do
28
- its(:last) { MUST eql: "Klop klop!" }
29
- end
30
- end
31
- end
@@ -1,26 +0,0 @@
1
- require_relative File.join 'dsl'
2
- require_relative File.join 'test'
3
-
4
- module Fix
5
- class Spec
6
- include DSL
7
-
8
- def initialize title = nil, &block
9
- @title = title
10
- @defs = {}
11
- @args = []
12
-
13
- instance_eval(&block)
14
-
15
- freeze
16
- end
17
-
18
- def test front_object, seed: Random.new_seed, color: true, stdout: STDOUT, stderr: STDERR
19
- Test.new front_object, seed: Random.new_seed, color: true, stdout: STDOUT, stderr: STDERR
20
- end
21
-
22
- def valid? front_object
23
- Test.new(front_object).pass?
24
- end
25
- end
26
- end