activefacts-api 1.8.1 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,124 +0,0 @@
1
- #
2
- # ActiveFacts tests: Value types in the Runtime API
3
- # Copyright (c) 2008 Clifford Heath. Read the LICENSE file.
4
- #
5
-
6
- describe "Value Type class definitions" do
7
- before :each do
8
- Object.send :remove_const, :Mod if Object.const_defined?("Mod")
9
- module Mod
10
- class Name < String
11
- value_type
12
- has_one :name
13
- end
14
- class Year < Int
15
- value_type
16
- has_one :name
17
- end
18
- class Weight < Real
19
- value_type
20
- has_one :name
21
- end
22
- class GivenName < Name
23
- end
24
- end
25
-
26
- @classes = [Mod::Name, Mod::GivenName, Mod::Year, Mod::Weight]
27
- @attrs = [:name, :name, :name, :name]
28
-
29
- end
30
-
31
- it "should respond_to verbalise" do
32
- @classes.each { |klass|
33
- klass.respond_to?(:verbalise).should be true
34
- }
35
- end
36
-
37
- it "should not pollute the value class" do
38
- @classes.each { |klass|
39
- if !@classes.include?(klass.superclass)
40
- klass.superclass.respond_to?(:verbalise).should_not be true
41
- end
42
- }
43
- end
44
-
45
- it "should return a string from verbalise" do
46
- @classes.each { |klass|
47
- v = klass.verbalise
48
- v.should_not be_nil
49
- v.should_not =~ /REVISIT/
50
- }
51
- end
52
-
53
- it "should respond_to vocabulary" do
54
- @classes.each { |klass|
55
- klass.respond_to?(:vocabulary).should be true
56
- }
57
- end
58
-
59
- it "should return the parent module as the vocabulary" do
60
- @classes.each { |klass|
61
- vocabulary = klass.vocabulary
62
- vocabulary.should == Mod
63
- }
64
- end
65
-
66
- it "should return a vocabulary that knows about this object_type" do
67
- @classes.each { |klass|
68
- vocabulary = klass.vocabulary
69
- vocabulary.respond_to?(:object_type).should be true
70
- vocabulary.object_type.has_key?(klass.basename).should be true
71
- }
72
- end
73
-
74
- it "should respond to roles()" do
75
- @classes.each { |klass|
76
- klass.respond_to?(:all_role).should be true
77
- }
78
- end
79
-
80
- it "should contain only the added role definitions" do
81
- @classes.each { |klass|
82
- num_roles = klass.all_role.size
83
- if klass == Mod::GivenName
84
- num_roles.should == 1
85
- elsif klass == Mod::Name
86
- num_roles.should == 5
87
- else
88
- num_roles.should == 1
89
- end
90
- }
91
- end
92
-
93
- it "should return the role definition" do
94
- # Check the role definition may not be accessed by passing an index:
95
- Mod::Name.all_role(0).should be_nil
96
-
97
- @classes.zip(@attrs).each { |klass, attr|
98
- klass.all_role(attr).should_not be_nil
99
- klass.all_role(attr.to_s).should_not be_nil
100
- # Check the role definition may be accessed by indexing the returned array:
101
- unless @classes.include?(klass.superclass)
102
- klass.all_role(attr).should_not be_nil
103
- # Check the role definition array by .include?
104
- klass.all_role.include?(attr).should be true
105
- end
106
- }
107
- end
108
-
109
- # REVISIT: role value constraints
110
-
111
- it "should fail on a non-ValueClass" do
112
- lambda{
113
- class NameNotString
114
- value_type
115
- end
116
- }.should raise_error(NameError)
117
- end
118
-
119
- it "should allow configuration of Role value through constructor using role name" do
120
- c = ActiveFacts::API::Constellation.new(Mod)
121
- w = c.Weight(9.0, :name => "pounds")
122
- w.name.should == "pounds"
123
- end
124
- end
@@ -1,9 +0,0 @@
1
- require 'simplecov'
2
-
3
- SimpleCov.start do
4
- add_filter "/spec/"
5
- add_filter "/lib/activefacts/tracer.rb"
6
- end
7
-
8
- # N.B. This must be loaded after SimpleCov.start
9
- require 'activefacts/api'
@@ -1,13 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'activefacts/api'
5
-
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
- RSpec.configure do |config|
11
-
12
- end
13
-
@@ -1,29 +0,0 @@
1
- if ENV["RSPEC_REPORT_EXCEPTIONS"]
2
- class Exception
3
- alias_method :old_initialize, :initialize
4
-
5
- def self.exceptions_seen
6
- @@seen ||= {}
7
- end
8
-
9
- def self.see args
10
- stack = caller[1..-1]
11
- # Don't show expected exceptions or RSpec internal ones
12
- return if caller.detect{|s| s =~ %r{rspec/matchers/raise_error}} or
13
- self.name =~ /^RSpec::/
14
- stack.reject!{|s| s =~ %r{/rspec/}}
15
- key = stack[0,4]+[self.name]
16
- return if exceptions_seen[key]
17
-
18
- exceptions_seen[key] = show = stack
19
- args[0] = args[0].to_str if args[0].class.name == "NameError::message"
20
- puts "#{self.name}#{args.inspect}:\n\t#{show*"\n\t"}"
21
- end
22
-
23
- def initialize *args, &b
24
- self.class.see args
25
-
26
- send(:old_initialize, *args, &b)
27
- end
28
- end
29
- end