opal-spec 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +0,0 @@
1
- module OpalSpec
2
- class ExpectationNotMetError < StandardError; end
3
-
4
- module Expectations
5
- def should matcher = nil
6
- if matcher
7
- matcher.match self
8
- else
9
- OpalSpec::PositiveOperatorMatcher.new self
10
- end
11
- end
12
-
13
- def should_not matcher = nil
14
- if matcher
15
- matcher.not_match self
16
- else
17
- OpalSpec::NegativeOperatorMatcher.new self
18
- end
19
- end
20
-
21
- def be_kind_of expected
22
- OpalSpec::BeKindOfMatcher.new expected
23
- end
24
-
25
- def be_nil
26
- OpalSpec::BeNilMatcher.new nil
27
- end
28
-
29
- def be_true
30
- OpalSpec::BeTrueMatcher.new true
31
- end
32
-
33
- def be_false
34
- OpalSpec::BeFalseMatcher.new false
35
- end
36
-
37
- def eq(expected)
38
- OpalSpec::EqlMatcher.new expected
39
- end
40
-
41
- def equal expected
42
- OpalSpec::EqualMatcher.new expected
43
- end
44
-
45
- def raise_error expected
46
- OpalSpec::RaiseErrorMatcher.new expected
47
- end
48
- end
49
- end
50
-
51
- class Object
52
- include OpalSpec::Expectations
53
- end
@@ -1,104 +0,0 @@
1
- module OpalSpec
2
- class Matcher
3
- def initialize actual
4
- @actual = actual
5
- end
6
-
7
- def failure message
8
- raise OpalSpec::ExpectationNotMetError, message
9
- end
10
- end
11
-
12
- class PositiveOperatorMatcher < Matcher
13
- def == expected
14
- if @actual == expected
15
- true
16
- else
17
- failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
18
- end
19
- end
20
- end
21
-
22
- class NegativeOperatorMatcher < Matcher
23
- def == expected
24
- if @actual == expected
25
- failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
26
- end
27
- end
28
- end
29
-
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}."
34
- end
35
- end
36
- end
37
-
38
- class BeNilMatcher < Matcher
39
- def match expected
40
- unless expected.nil?
41
- failure "expected #{expected.inspect} to be nil."
42
- end
43
- end
44
- end
45
-
46
- class BeTrueMatcher < Matcher
47
- def match expected
48
- unless expected == true
49
- failure "expected #{expected.inspect} to be true."
50
- end
51
- end
52
- end
53
-
54
- class BeFalseMatcher < Matcher
55
- def match expected
56
- unless expected == false
57
- failure "expected #{expected.inspect} to be false."
58
- end
59
- end
60
- end
61
-
62
- class EqlMatcher < Matcher
63
- def match(expected)
64
- unless expected == @actual
65
- failure "expected: #{expected.inspect}, got: #{@actual.inspect} (using ==)."
66
- end
67
- end
68
-
69
- def not_match(expected)
70
- if expected.equal? @actual
71
- failure "expected: #{expected.inspect} not to be #{@actual.inspect} (using ==)."
72
- end
73
- end
74
- end
75
-
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}."
80
- end
81
- end
82
-
83
- def not_match expected
84
- if expected.equal? @actual
85
- failure "expected #{@actual.inspect} not to be equal to #{expected.inspect}."
86
- end
87
- end
88
- end
89
-
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
98
-
99
- if should_raise
100
- failure "expected #{@actual} to be raised, but nothing was."
101
- end
102
- end
103
- end
104
- end
@@ -1,91 +0,0 @@
1
- module OpalSpec
2
- class PhantomFormatter
3
- def initialize
4
- @examples = []
5
- @failed_examples = []
6
- end
7
-
8
- def log_green(str)
9
- `console.log('\\033[32m' + str + '\\033[0m')`
10
- end
11
-
12
- def log_red(str)
13
- `console.log('\\033[31m' + str + '\\033[0m')`
14
- end
15
-
16
- def log(str)
17
- `console.log(str)`
18
- end
19
-
20
- def start
21
- @start_time = Time.now.to_f
22
- end
23
-
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}"
34
-
35
- exception = example.exception
36
- case exception
37
- when OpalSpec::ExpectationNotMetError
38
- output = exception.message
39
- else
40
- output = "#{exception.class.name}: #{exception.message}\n"
41
- output += " #{exception.backtrace.join "\n "}\n"
42
- end
43
- log_red " #{output}"
44
- end
45
-
46
- log "\nFinished"
47
- log_red "#{example_count} examples, #{@failed_examples.size} failures (time taken: #{time})"
48
- finish_with_code(1)
49
- end
50
- end
51
-
52
- def finish_with_code(code)
53
- %x{
54
- if (typeof(phantom) !== 'undefined') {
55
- return phantom.exit(code);
56
- }
57
- else {
58
- window.OPAL_SPEC_CODE = code;
59
- }
60
- }
61
- end
62
-
63
- def example_group_started group
64
- @example_group = group
65
- @example_group_failed = false
66
- log "\n#{group.description}"
67
- end
68
-
69
- def example_group_finished group
70
- end
71
-
72
- def example_started example
73
- @examples << example
74
- @example = example
75
- end
76
-
77
- def example_failed example
78
- @failed_examples << example
79
- @example_group_failed = true
80
- log_red " #{example.description}"
81
- end
82
-
83
- def example_passed example
84
- log_green " #{example.description}"
85
- end
86
-
87
- def example_count
88
- @examples.size
89
- end
90
- end
91
- end
@@ -1,78 +0,0 @@
1
- module OpalSpec
2
- class Runner
3
- def self.in_browser?
4
- %x{
5
- if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
6
- return true;
7
- }
8
-
9
- return false;
10
- }
11
- end
12
-
13
- def self.in_phantom?
14
- %x{
15
- if (typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined') {
16
- return true;
17
- }
18
-
19
- return false;
20
- }
21
- end
22
-
23
- def self.autorun
24
- if in_browser?
25
- %x{
26
- setTimeout(function() {
27
- #{ Runner.new.run };
28
- }, 0);
29
- }
30
- else
31
- Runner.new.run
32
- end
33
- end
34
-
35
- def initialize
36
- if Runner.in_phantom?
37
- @formatter = PhantomFormatter.new
38
- elsif Runner.in_browser?
39
- @formatter = BrowserFormatter.new
40
- end
41
- end
42
-
43
- def run
44
- @groups = ExampleGroup.example_groups.dup
45
- @formatter.start
46
- run_next_group
47
- end
48
-
49
- def run_next_group
50
- if @groups.empty?
51
- @formatter.finish
52
- else
53
- @groups.shift.run self
54
- end
55
- end
56
-
57
- def example_group_started group
58
- @formatter.example_group_started group
59
- end
60
-
61
- def example_group_finished group
62
- @formatter.example_group_finished group
63
- run_next_group
64
- end
65
-
66
- def example_started example
67
- @formatter.example_started example
68
- end
69
-
70
- def example_passed example
71
- @formatter.example_passed example
72
- end
73
-
74
- def example_failed example
75
- @formatter.example_failed example
76
- end
77
- end
78
- end
@@ -1,3 +0,0 @@
1
- module OpalSpec
2
- VERSION = '0.2.6'
3
- end