opal-spec 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,94 +1,92 @@
1
- module Opal
2
- module Spec
3
- class ExampleGroup
4
- @example_groups = []
5
- def self.example_groups
6
- @example_groups
7
- end
1
+ module Spec
2
+ class ExampleGroup
3
+ @example_groups = []
4
+ def self.example_groups
5
+ @example_groups
6
+ end
8
7
 
9
- @stack = []
10
- def self.create desc, block
11
- group = self.new desc, @stack.last
12
- @example_groups << group
8
+ @stack = []
9
+ def self.create desc, block
10
+ group = self.new desc, @stack.last
11
+ @example_groups << group
13
12
 
14
- @stack << group
15
- group.instance_eval &block
16
- @stack.pop
17
- end
13
+ @stack << group
14
+ group.instance_eval &block
15
+ @stack.pop
16
+ end
18
17
 
19
- def initialize desc, parent
20
- @desc = desc.to_s
21
- @parent = parent
22
- @examples = []
18
+ def initialize desc, parent
19
+ @desc = desc.to_s
20
+ @parent = parent
21
+ @examples = []
23
22
 
24
- @before_hooks = []
25
- @after_hooks = []
26
- end
23
+ @before_hooks = []
24
+ @after_hooks = []
25
+ end
27
26
 
28
- def it(desc, &block)
29
- @examples << Example.new(self, desc, block)
30
- end
27
+ def it(desc, &block)
28
+ @examples << Example.new(self, desc, block)
29
+ end
31
30
 
32
- def async(desc, &block)
33
- example = Example.new(self, desc, block)
34
- example.asynchronous = true
35
- @examples << example
36
- end
31
+ def async(desc, &block)
32
+ example = Example.new(self, desc, block)
33
+ example.asynchronous = true
34
+ @examples << example
35
+ end
37
36
 
38
- def it_behaves_like(*objs)
39
- end
37
+ def it_behaves_like(*objs)
38
+ end
40
39
 
41
- def before type = :each, &block
42
- raise "unsupported before type: #{type}" unless type == :each
43
- @before_hooks << block
44
- end
40
+ def before type = :each, &block
41
+ raise "unsupported before type: #{type}" unless type == :each
42
+ @before_hooks << block
43
+ end
45
44
 
46
- def after type = :each, &block
47
- raise "unsupported after type: #{type}" unless type == :each
48
- @after_hooks << block
49
- end
45
+ def after type = :each, &block
46
+ raise "unsupported after type: #{type}" unless type == :each
47
+ @after_hooks << block
48
+ end
50
49
 
51
- def before_hooks
52
- @parent ? [].concat(@parent.before_hooks).concat(@before_hooks) : @before_hooks
53
- end
50
+ def before_hooks
51
+ @parent ? [].concat(@parent.before_hooks).concat(@before_hooks) : @before_hooks
52
+ end
54
53
 
55
- def after_hooks
56
- @parent ? [].concat(@parent.after_hooks).concat(@after_hooks) : @after_hooks
57
- end
54
+ def after_hooks
55
+ @parent ? [].concat(@parent.after_hooks).concat(@after_hooks) : @after_hooks
56
+ end
58
57
 
59
- def run(runner)
60
- @runner = runner
61
- @runner.example_group_started self
58
+ def run(runner)
59
+ @runner = runner
60
+ @runner.example_group_started self
62
61
 
63
- @running_examples = @examples.dup
64
- run_next_example
65
- end
62
+ @running_examples = @examples.dup
63
+ run_next_example
64
+ end
66
65
 
67
- def run_next_example
68
- if @running_examples.empty?
69
- @runner.example_group_finished self
70
- else
71
- @running_examples.shift.run
72
- end
66
+ def run_next_example
67
+ if @running_examples.empty?
68
+ @runner.example_group_finished self
69
+ else
70
+ @running_examples.shift.run
73
71
  end
72
+ end
74
73
 
75
- def example_started(example)
76
- @runner.example_started(example)
77
- end
74
+ def example_started(example)
75
+ @runner.example_started(example)
76
+ end
78
77
 
79
- def example_passed(example)
80
- @runner.example_passed(example)
81
- run_next_example
82
- end
78
+ def example_passed(example)
79
+ @runner.example_passed(example)
80
+ run_next_example
81
+ end
83
82
 
84
- def example_failed(example)
85
- @runner.example_failed(example)
86
- run_next_example
87
- end
83
+ def example_failed(example)
84
+ @runner.example_failed(example)
85
+ run_next_example
86
+ end
88
87
 
89
- def description
90
- @parent ? "#{@parent.description} #{@desc}" : @desc
91
- end
88
+ def description
89
+ @parent ? "#{@parent.description} #{@desc}" : @desc
92
90
  end
93
91
  end
94
92
  end
@@ -1,55 +1,54 @@
1
- module Opal
2
- module Spec
3
- class ExpectationNotMetError < StandardError; end
4
-
5
- module Expectations
6
- def should matcher = nil
7
- if matcher
8
- matcher.match self
9
- else
10
- Opal::Spec::PositiveOperatorMatcher.new self
11
- end
12
- end
13
1
 
14
- def should_not matcher = nil
15
- if matcher
16
- matcher.not_match self
17
- else
18
- Opal::Spec::NegativeOperatorMatcher.new self
19
- end
20
- end
2
+ module Spec
3
+ class ExpectationNotMetError < StandardError; end
21
4
 
22
- def be_kind_of expected
23
- Opal::Spec::BeKindOfMatcher.new expected
5
+ module Expectations
6
+ def should matcher = nil
7
+ if matcher
8
+ matcher.match self
9
+ else
10
+ Spec::PositiveOperatorMatcher.new self
24
11
  end
12
+ end
25
13
 
26
- def be_nil
27
- Opal::Spec::BeNilMatcher.new nil
14
+ def should_not matcher = nil
15
+ if matcher
16
+ matcher.not_match self
17
+ else
18
+ Spec::NegativeOperatorMatcher.new self
28
19
  end
20
+ end
29
21
 
30
- def be_true
31
- Opal::Spec::BeTrueMatcher.new true
32
- end
22
+ def be_kind_of expected
23
+ Spec::BeKindOfMatcher.new expected
24
+ end
33
25
 
34
- def be_false
35
- Opal::Spec::BeFalseMatcher.new false
36
- end
26
+ def be_nil
27
+ Spec::BeNilMatcher.new nil
28
+ end
37
29
 
38
- def eq(expected)
39
- Opal::Spec::EqlMatcher.new expected
40
- end
30
+ def be_true
31
+ Spec::BeTrueMatcher.new true
32
+ end
41
33
 
42
- def equal expected
43
- Opal::Spec::EqualMatcher.new expected
44
- end
34
+ def be_false
35
+ Spec::BeFalseMatcher.new false
36
+ end
45
37
 
46
- def raise_error expected
47
- Opal::Spec::RaiseErrorMatcher.new expected
48
- end
38
+ def eq(expected)
39
+ Spec::EqlMatcher.new expected
40
+ end
41
+
42
+ def equal expected
43
+ Spec::EqualMatcher.new expected
44
+ end
45
+
46
+ def raise_error expected
47
+ Spec::RaiseErrorMatcher.new expected
49
48
  end
50
49
  end
51
50
  end
52
51
 
53
52
  class Object
54
- include Opal::Spec::Expectations
53
+ include Spec::Expectations
55
54
  end
@@ -1,9 +1,9 @@
1
1
  module Kernel
2
- def describe desc, &block
3
- Opal::Spec::ExampleGroup.create desc, block
2
+ def describe(desc, &block)
3
+ Spec::ExampleGroup.create desc, block
4
4
  end
5
5
 
6
- def mock obj
6
+ def mock(obj)
7
7
  Object.new
8
8
  end
9
9
  end
@@ -1,105 +1,103 @@
1
- module Opal
2
- module Spec
3
- class Matcher
4
- def initialize actual
5
- @actual = actual
6
- end
1
+ module Spec
2
+ class Matcher
3
+ def initialize(actual)
4
+ @actual = actual
5
+ end
7
6
 
8
- def failure message
9
- raise Opal::Spec::ExpectationNotMetError, message
10
- end
7
+ def failure(message)
8
+ raise Spec::ExpectationNotMetError, message
11
9
  end
10
+ end
12
11
 
13
- class PositiveOperatorMatcher < Matcher
14
- def == expected
15
- if @actual == expected
16
- true
17
- else
18
- failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
19
- end
12
+ class PositiveOperatorMatcher < Matcher
13
+ def == expected
14
+ if @actual == expected
15
+ true
16
+ else
17
+ failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
20
18
  end
21
19
  end
20
+ end
22
21
 
23
- class NegativeOperatorMatcher < Matcher
24
- def == expected
25
- if @actual == expected
26
- failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
27
- end
22
+ class NegativeOperatorMatcher < Matcher
23
+ def == expected
24
+ if @actual == expected
25
+ failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
28
26
  end
29
27
  end
28
+ end
30
29
 
31
- class BeKindOfMatcher < Matcher
32
- def match expected
33
- unless expected.kind_of? @actual
34
- failure "expected #{expected.inspect} to be a kind of #{@actual.name}, not #{expected.class.name}."
35
- end
30
+ class BeKindOfMatcher < Matcher
31
+ def match expected
32
+ unless expected.kind_of? @actual
33
+ failure "expected #{expected.inspect} to be a kind of #{@actual.name}, not #{expected.class.name}."
36
34
  end
37
35
  end
36
+ end
38
37
 
39
- class BeNilMatcher < Matcher
40
- def match expected
41
- unless expected.nil?
42
- failure "expected #{expected.inspect} to be nil."
43
- end
38
+ class BeNilMatcher < Matcher
39
+ def match expected
40
+ unless expected.nil?
41
+ failure "expected #{expected.inspect} to be nil."
44
42
  end
45
43
  end
44
+ end
46
45
 
47
- class BeTrueMatcher < Matcher
48
- def match expected
49
- unless expected == true
50
- failure "expected #{expected.inspect} to be true."
51
- end
46
+ class BeTrueMatcher < Matcher
47
+ def match expected
48
+ unless expected == true
49
+ failure "expected #{expected.inspect} to be true."
52
50
  end
53
51
  end
52
+ end
54
53
 
55
- class BeFalseMatcher < Matcher
56
- def match expected
57
- unless expected == false
58
- failure "expected #{expected.inspect} to be false."
59
- end
54
+ class BeFalseMatcher < Matcher
55
+ def match expected
56
+ unless expected == false
57
+ failure "expected #{expected.inspect} to be false."
60
58
  end
61
59
  end
60
+ end
62
61
 
63
- class EqlMatcher < Matcher
64
- def match(expected)
65
- unless expected == @actual
66
- failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
67
- end
62
+ class EqlMatcher < Matcher
63
+ def match(expected)
64
+ unless expected == @actual
65
+ failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
68
66
  end
67
+ end
69
68
 
70
- def not_match(expected)
71
- if expected.equal? @actual
72
- failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
73
- end
69
+ def not_match(expected)
70
+ if expected.equal? @actual
71
+ failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
74
72
  end
75
73
  end
74
+ end
76
75
 
77
- class EqualMatcher < Matcher
78
- def match expected
79
- unless expected.equal? @actual
80
- failure "expected #{@actual.inspect} to be the same as #{expected.inspect}."
81
- end
76
+ class EqualMatcher < Matcher
77
+ def match expected
78
+ unless expected.equal? @actual
79
+ failure "expected #{@actual.inspect} to be the same as #{expected.inspect}."
82
80
  end
81
+ end
83
82
 
84
- def not_match expected
85
- if expected.equal? @actual
86
- failure "expected #{@actual.inspect} not to be equal to #{expected.inspect}."
87
- end
83
+ def not_match expected
84
+ if expected.equal? @actual
85
+ failure "expected #{@actual.inspect} not to be equal to #{expected.inspect}."
88
86
  end
89
87
  end
88
+ end
90
89
 
91
- class RaiseErrorMatcher < Matcher
92
- def match block
93
- should_raise = false
94
- begin
95
- block.call
96
- should_raise = true
97
- rescue => e
98
- end
90
+ class RaiseErrorMatcher < Matcher
91
+ def match block
92
+ should_raise = false
93
+ begin
94
+ block.call
95
+ should_raise = true
96
+ rescue => e
97
+ end
99
98
 
100
- if should_raise
101
- failure "expected #{@actual} to be raised, but nothing was."
102
- end
99
+ if should_raise
100
+ failure "expected #{@actual} to be raised, but nothing was."
103
101
  end
104
102
  end
105
103
  end
@@ -1,93 +1,91 @@
1
- module Opal
2
- module Spec
3
- class PhantomFormatter
4
- def initialize
5
- @examples = []
6
- @failed_examples = []
7
- end
1
+ module Spec
2
+ class PhantomFormatter
3
+ def initialize
4
+ @examples = []
5
+ @failed_examples = []
6
+ end
8
7
 
9
- def log_green(str)
10
- `console.log('\\033[32m' + str + '\\033[0m')`
11
- end
8
+ def log_green(str)
9
+ `console.log('\\033[32m' + str + '\\033[0m')`
10
+ end
12
11
 
13
- def log_red(str)
14
- `console.log('\\033[31m' + str + '\\033[0m')`
15
- end
12
+ def log_red(str)
13
+ `console.log('\\033[31m' + str + '\\033[0m')`
14
+ end
16
15
 
17
- def log(str)
18
- `console.log(str)`
19
- end
16
+ def log(str)
17
+ `console.log(str)`
18
+ end
20
19
 
21
- def start
22
- @start_time = Time.now.to_f
23
- end
20
+ def start
21
+ @start_time = Time.now.to_f
22
+ end
24
23
 
25
- def finish
26
- time = Time.now.to_f - @start_time
27
- if @failed_examples.empty?
28
- log "\nFinished"
29
- log_green "#{example_count} examples, 0 failures (time taken: #{time})"
30
- finish_with_code(0)
31
- else
32
- log "\nFailures:"
33
- @failed_examples.each_with_index do |example, idx|
34
- log "\n #{idx+1}. #{example.example_group.description} #{example.description}"
24
+ def finish
25
+ time = Time.now.to_f - @start_time
26
+ if @failed_examples.empty?
27
+ log "\nFinished"
28
+ log_green "#{example_count} examples, 0 failures (time taken: #{time})"
29
+ finish_with_code(0)
30
+ else
31
+ log "\nFailures:"
32
+ @failed_examples.each_with_index do |example, idx|
33
+ log "\n #{idx+1}. #{example.example_group.description} #{example.description}"
35
34
 
36
- exception = example.exception
37
- case exception
38
- when Opal::Spec::ExpectationNotMetError
39
- output = exception.message
40
- else
41
- output = "#{exception.class.name}: #{exception.message}\n"
42
- output += " #{exception.backtrace.join "\n "}\n"
43
- end
44
- log_red " #{output}"
35
+ exception = example.exception
36
+ case exception
37
+ when Spec::ExpectationNotMetError
38
+ output = exception.message
39
+ else
40
+ output = "#{exception.class.name}: #{exception.message}\n"
41
+ output += " #{exception.backtrace.join "\n "}\n"
45
42
  end
46
-
47
- log "\nFinished"
48
- log_red "#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
49
- finish_with_code(1)
43
+ log_red " #{output}"
50
44
  end
45
+
46
+ log "\nFinished"
47
+ log_red "#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
48
+ finish_with_code(1)
51
49
  end
50
+ end
52
51
 
53
- def finish_with_code(code)
54
- %x{
55
- if (typeof(phantom) !== 'undefined') {
56
- return phantom.exit(code);
57
- }
58
- else {
59
- window.OPAL_SPEC_CODE = code;
60
- }
52
+ def finish_with_code(code)
53
+ %x{
54
+ if (typeof(phantom) !== 'undefined') {
55
+ return phantom.exit(code);
61
56
  }
62
- end
57
+ else {
58
+ window.OPAL_SPEC_CODE = code;
59
+ }
60
+ }
61
+ end
63
62
 
64
- def example_group_started group
65
- @example_group = group
66
- @example_group_failed = false
67
- log "\n#{group.description}"
68
- end
63
+ def example_group_started group
64
+ @example_group = group
65
+ @example_group_failed = false
66
+ log "\n#{group.description}"
67
+ end
69
68
 
70
- def example_group_finished group
71
- end
69
+ def example_group_finished group
70
+ end
72
71
 
73
- def example_started example
74
- @examples << example
75
- @example = example
76
- end
72
+ def example_started example
73
+ @examples << example
74
+ @example = example
75
+ end
77
76
 
78
- def example_failed example
79
- @failed_examples << example
80
- @example_group_failed = true
81
- log_red " #{example.description}"
82
- end
77
+ def example_failed example
78
+ @failed_examples << example
79
+ @example_group_failed = true
80
+ log_red " #{example.description}"
81
+ end
83
82
 
84
- def example_passed example
85
- log_green " #{example.description}"
86
- end
83
+ def example_passed example
84
+ log_green " #{example.description}"
85
+ end
87
86
 
88
- def example_count
89
- @examples.size
90
- end
87
+ def example_count
88
+ @examples.size
91
89
  end
92
90
  end
93
91
  end