yuml 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/README.md +105 -0
- data/Rakefile +8 -0
- data/lib/yuml.rb +2 -1
- data/lib/yuml/class.rb +12 -2
- data/spec/spec_helper.rb +98 -0
- data/spec/yuml_class_spec.rb +149 -0
- data/spec/yuml_note_spec.rb +11 -0
- data/spec/yuml_relationship_spec.rb +100 -0
- data/spec/yuml_spec.rb +74 -0
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99b5862e06b3aa1de18dfeb4ee79d1e4c126d27c
|
4
|
+
data.tar.gz: 2a417c8ffb3950322453492712e8fb3271ba6de6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6711c541ea638decf9ce1e9d52980b1a5ec1402fbe216223dd3cc4acf0e81a21e66fd5b383b544a7506ec864652cff795c16ce4d0112a9885d2097da4fb969d4
|
7
|
+
data.tar.gz: f0921550ab9e6a33c437210cec7770c760cfc32d58b0c0ac5dc31f9793b2b77c59412298b593ff1320e53ed236be635c0cd753798a4cd0297f14185e2eb54a54
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Derek Stride
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# yuml
|
2
|
+
|
3
|
+
A Ruby DSL for generating UML built on yuml.me
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
To build a UML document start with this block of code. Everything inside the block will be used to descibe the uml document you want to create.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
YUML.generate(file: 'tmp.pdf') do |uml|
|
11
|
+
...
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
### Generating a Class
|
16
|
+
|
17
|
+
To generate a class for the document use `uml.class` and pass a code block in to configure it. It accepts the following methods for configuration.
|
18
|
+
|
19
|
+
* name (required)
|
20
|
+
* variables
|
21
|
+
* methods
|
22
|
+
|
23
|
+
#### Example
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
document = uml.class do
|
27
|
+
name 'Document'
|
28
|
+
variables '-title: String', '-body: String'
|
29
|
+
methods(
|
30
|
+
'+add_section(id: int, content: String, style: Symbol)',
|
31
|
+
'+remove_section(id: int)',
|
32
|
+
'+edit_section(id: int, content: String, style: Symbol)'
|
33
|
+
)
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
### Adding Relationships
|
38
|
+
|
39
|
+
After generating some classes to add relationships to them use the following `YUML::Class` methods.
|
40
|
+
|
41
|
+
* `has_a(node, options = {})`
|
42
|
+
* `is_a(node, options = {})`
|
43
|
+
* `associated_with(node, options = {})`
|
44
|
+
* `attach_note(content, options = {})` *options include color!
|
45
|
+
|
46
|
+
`has_a` can be **composition** or **aggregation** but defaults to aggregation.
|
47
|
+
|
48
|
+
`is_a` can be **inheritance** or **interface** but defaults to inheritance.
|
49
|
+
|
50
|
+
`associated_with` can be **association**, **directed_association**, **two_way_association**, or **dependancy** but defaults to directed_association.
|
51
|
+
|
52
|
+
#### Example
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
document.has_a(picture, cardinality: '0..*')
|
56
|
+
document.is_a(content)
|
57
|
+
|
58
|
+
picture.is_a(content, type: :interface)
|
59
|
+
content.associated_with(content, type: dependency)
|
60
|
+
document.attach_note('This is a document', color: :green)
|
61
|
+
```
|
62
|
+
|
63
|
+
### Adding notes
|
64
|
+
|
65
|
+
You can add notes too the document itself as well as attached to class
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
YUML.generate(file: 'tmp.pd') do |uml|
|
69
|
+
uml.attach_note('Cool UML Tool?')
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
### Test it Out
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
require 'yuml'
|
78
|
+
|
79
|
+
YUML.generate(file: 'example.pdf') do |uml|
|
80
|
+
document = uml.class do
|
81
|
+
name 'Document'
|
82
|
+
variables '-title: String', '-body: String'
|
83
|
+
methods(
|
84
|
+
'+add_section(id: int, content: String, style: Symbol)',
|
85
|
+
'+remove_section(id: int)',
|
86
|
+
'+edit_section(id: int, content: String, style: Symbol)'
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
picture = uml.class do
|
91
|
+
name 'Picture'
|
92
|
+
end
|
93
|
+
|
94
|
+
content = uml.class do
|
95
|
+
name 'Content'
|
96
|
+
end
|
97
|
+
|
98
|
+
document.has_a(picture, cardinality: '0..*')
|
99
|
+
document.is_a(content)
|
100
|
+
|
101
|
+
picture.is_a(content)
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
![output](https://cloud.githubusercontent.com/assets/6456191/13322710/bc91e81c-dba3-11e5-88d3-16e1980f7cb4.png)
|
data/Rakefile
ADDED
data/lib/yuml.rb
CHANGED
data/lib/yuml/class.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module YUML
|
2
2
|
# Represents a yUML Class
|
3
3
|
class Class
|
4
|
-
attr_writer :name
|
4
|
+
attr_writer :name, :interface
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@methods = []
|
@@ -11,7 +11,12 @@ module YUML
|
|
11
11
|
|
12
12
|
def name(name = nil)
|
13
13
|
@name = name if name
|
14
|
-
@name
|
14
|
+
"#{normalized_interface}#{@name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def interface(interface = nil)
|
18
|
+
@interface = interface if interface
|
19
|
+
@interface
|
15
20
|
end
|
16
21
|
|
17
22
|
def variables(*args)
|
@@ -67,6 +72,11 @@ module YUML
|
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
75
|
+
def normalized_interface
|
76
|
+
name interface unless @name
|
77
|
+
return normalize(['<<interface>>']).first << ';' if interface
|
78
|
+
end
|
79
|
+
|
70
80
|
def attributes(attrs)
|
71
81
|
"|#{attrs.join(';')}" unless attrs.empty?
|
72
82
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
require 'webmock/rspec'
|
20
|
+
require 'fakefs/spec_helpers'
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# rspec-expectations config goes here. You can use an alternate
|
23
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
24
|
+
# assertions if you prefer.
|
25
|
+
config.expect_with :rspec do |expectations|
|
26
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
27
|
+
# and `failure_message` of custom matchers include text for helper methods
|
28
|
+
# defined using `chain`, e.g.:
|
29
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
30
|
+
# # => "be bigger than 2 and smaller than 4"
|
31
|
+
# ...rather than:
|
32
|
+
# # => "be bigger than 2"
|
33
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
34
|
+
end
|
35
|
+
|
36
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
37
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
38
|
+
config.mock_with :rspec do |mocks|
|
39
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
40
|
+
# a real object. This is generally recommended, and will default to
|
41
|
+
# `true` in RSpec 4.
|
42
|
+
mocks.verify_partial_doubles = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# The settings below are suggested to provide a good initial experience
|
46
|
+
# with RSpec, but feel free to customize to your heart's content.
|
47
|
+
=begin
|
48
|
+
# These two settings work together to allow you to limit a spec run
|
49
|
+
# to individual examples or groups you care about by tagging them with
|
50
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
51
|
+
# get run.
|
52
|
+
config.filter_run :focus
|
53
|
+
config.run_all_when_everything_filtered = true
|
54
|
+
|
55
|
+
# Allows RSpec to persist some state between runs in order to support
|
56
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
57
|
+
# you configure your source control system to ignore this file.
|
58
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
59
|
+
|
60
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
61
|
+
# recommended. For more details, see:
|
62
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
63
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
64
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
65
|
+
config.disable_monkey_patching!
|
66
|
+
|
67
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
68
|
+
# be too noisy due to issues in dependencies.
|
69
|
+
config.warnings = true
|
70
|
+
|
71
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
72
|
+
# file, and it's useful to allow more verbose output when running an
|
73
|
+
# individual spec file.
|
74
|
+
if config.files_to_run.one?
|
75
|
+
# Use the documentation formatter for detailed output,
|
76
|
+
# unless a formatter has already been configured
|
77
|
+
# (e.g. via a command-line flag).
|
78
|
+
config.default_formatter = 'doc'
|
79
|
+
end
|
80
|
+
|
81
|
+
# Print the 10 slowest examples and example groups at the
|
82
|
+
# end of the spec run, to help surface which specs are running
|
83
|
+
# particularly slow.
|
84
|
+
config.profile_examples = 10
|
85
|
+
|
86
|
+
# Run specs in random order to surface order dependencies. If you find an
|
87
|
+
# order dependency and want to debug it, you can fix the order by providing
|
88
|
+
# the seed, which is printed after each run.
|
89
|
+
# --seed 1234
|
90
|
+
config.order = :random
|
91
|
+
|
92
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
93
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
94
|
+
# test failures related to randomization by passing the same `--seed` value
|
95
|
+
# as the one that triggered the failure.
|
96
|
+
Kernel.srand config.seed
|
97
|
+
=end
|
98
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/yuml'
|
3
|
+
|
4
|
+
describe YUML::Class do
|
5
|
+
before :each do
|
6
|
+
@uut = YUML::Class.new
|
7
|
+
@doc = YUML.class do |c|
|
8
|
+
c.name 'Document'
|
9
|
+
c.variables('+foo', '+bar')
|
10
|
+
c.methods(
|
11
|
+
'+foo(name, other = nil)',
|
12
|
+
'+bar()'
|
13
|
+
)
|
14
|
+
end
|
15
|
+
@pic = YUML.class do |c|
|
16
|
+
c.name 'Picture'
|
17
|
+
c.methods('+bar()')
|
18
|
+
c.variables('-foo')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#new' do
|
23
|
+
it 'takes no parameters and returns a YUML::Class object' do
|
24
|
+
expect(@uut).to be_an_instance_of(YUML::Class)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#name' do
|
29
|
+
it 'takes a name and updates the class' do
|
30
|
+
@uut.name 'Document'
|
31
|
+
expect(@uut.to_s).to eq '[Document]'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should work with name= as well' do
|
35
|
+
@uut.name = 'Document'
|
36
|
+
expect(@uut.to_s).to eq '[Document]'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#interface' do
|
41
|
+
before :all do
|
42
|
+
left = "#{YUML::ESCAPE_CHARACTERS['<']}" * 2
|
43
|
+
right = "#{YUML::ESCAPE_CHARACTERS['>']}" * 2
|
44
|
+
@interface_uml = "[#{left}interface#{right};Document]"
|
45
|
+
end
|
46
|
+
it 'takes a interface and updates the class' do
|
47
|
+
@uut.interface 'Document'
|
48
|
+
expect(@uut.to_s).to eq @interface_uml
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should work with interface= as well' do
|
52
|
+
@uut.interface = 'Document'
|
53
|
+
expect(@uut.to_s).to eq @interface_uml
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#variables' do
|
58
|
+
before :each do
|
59
|
+
@uut.name 'Document'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'takes symbols and adds it to the class' do
|
63
|
+
@uut.variables(:foo, :bar)
|
64
|
+
expect(@uut.to_s).to eq '[Document|foo;bar]'
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'takes strings and adds it to the class' do
|
68
|
+
@uut.variables('+foo:String', '-bar:int')
|
69
|
+
expect(@uut.to_s).to eq '[Document|+foo:String;-bar:int]'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#methods' do
|
74
|
+
it 'takes an array of symbols and adds it to the class' do
|
75
|
+
@uut.name 'Document'
|
76
|
+
@uut.methods(
|
77
|
+
'+foo(name, other = nil)',
|
78
|
+
'-bar()'
|
79
|
+
)
|
80
|
+
expect(@uut.to_s).to eq "[Document|+foo(name#{YUML::ESCAPE_CHARACTERS[',']} other = nil);-bar()]"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#has_a' do
|
85
|
+
it 'should handle aggregation' do
|
86
|
+
@doc.has_a(@pic)
|
87
|
+
expect(@doc.relationships).to eq '[Document]+->[Picture]'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should handle cardinality' do
|
91
|
+
@doc.has_a(@pic, cardinality: '*')
|
92
|
+
expect(@doc.relationships).to eq '[Document]+-*>[Picture]'
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should handle composition and cardinality' do
|
96
|
+
@doc.has_a(@pic, type: :composition, cardinality: [0, '*'])
|
97
|
+
expect(@doc.relationships).to eq '[Document]++0-*>[Picture]'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#is_a' do
|
102
|
+
it 'should handle inheritance' do
|
103
|
+
@doc.is_a(@pic, type: :inheritance)
|
104
|
+
expect(@doc.relationships).to eq '[Picture]^-[Document]'
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should handle interfaces' do
|
108
|
+
@pic.interface 'Picture'
|
109
|
+
@doc.is_a(@pic, type: :interface)
|
110
|
+
left = "#{YUML::ESCAPE_CHARACTERS['<']}" * 2
|
111
|
+
right = "#{YUML::ESCAPE_CHARACTERS['>']}" * 2
|
112
|
+
expect(@doc.relationships).to eq "[#{left}interface#{right};Picture]^-.-[Document]"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#associated_with' do
|
117
|
+
it 'should handle a default association' do
|
118
|
+
@doc.associated_with(@pic)
|
119
|
+
expect(@doc.relationships).to eq '[Document]->[Picture]'
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should handle an association with cardinality' do
|
123
|
+
@doc.associated_with(@pic, cardinality: %w(uses used))
|
124
|
+
expect(@doc.relationships).to eq '[Document]uses-used>[Picture]'
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should handle a bi directional associations with cardinality' do
|
128
|
+
@doc.associated_with(@pic, type: :two_way_association, cardinality: ['used by'])
|
129
|
+
expect(@doc.relationships).to eq '[Document]<-used by>[Picture]'
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should handle a undirected association' do
|
133
|
+
@doc.associated_with(@pic, type: :association, cardinality: ['used by'])
|
134
|
+
expect(@doc.relationships).to eq '[Document]-used by[Picture]'
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should handle a dependency' do
|
138
|
+
@doc.associated_with(@pic, type: :dependency, cardinality: %w(uses used))
|
139
|
+
expect(@doc.relationships).to eq '[Document]uses-.-used>[Picture]'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#attach_note' do
|
144
|
+
it 'should add a note to the relationships' do
|
145
|
+
@doc.attach_note('This diagram blongs to Derek Stride')
|
146
|
+
expect(@doc.relationships).to eq '[Document]-[note: This diagram blongs to Derek Stride{bg:cornsilk}]'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/yuml'
|
3
|
+
|
4
|
+
describe YUML::Note do
|
5
|
+
describe '#create' do
|
6
|
+
it 'should return a formatted string' do
|
7
|
+
note = YUML::Note.create('This diagram blongs to Derek Stride', color: :green)
|
8
|
+
expect(note).to eq '[note: This diagram blongs to Derek Stride{bg:green}]'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/yuml'
|
3
|
+
|
4
|
+
describe YUML::Relationship do
|
5
|
+
describe '#inheritance' do
|
6
|
+
it 'should return the default inheritance relationship' do
|
7
|
+
expect(YUML::Relationship.inheritance).to eq '^-'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#interface' do
|
12
|
+
it 'should return the default interface relationship' do
|
13
|
+
expect(YUML::Relationship.interface).to eq '^-.-'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#composition' do
|
18
|
+
it 'should return the default composition relationship' do
|
19
|
+
expect(YUML::Relationship.composition).to eq '++->'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should handle a single cardinality' do
|
23
|
+
expect(YUML::Relationship.composition('*')).to eq '++-*>'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should handle a two sided cardinality' do
|
27
|
+
expect(YUML::Relationship.composition('1', '*')).to eq '++1-*>'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#aggregation' do
|
32
|
+
it 'should return the default aggregation relationship' do
|
33
|
+
expect(YUML::Relationship.aggregation).to eq '+->'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should handle a single cardinality' do
|
37
|
+
expect(YUML::Relationship.aggregation('*')).to eq '+-*>'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should handle a two sided cardinality' do
|
41
|
+
expect(YUML::Relationship.aggregation('1', '*')).to eq '+1-*>'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#association' do
|
46
|
+
it 'should return the default association relationship' do
|
47
|
+
expect(YUML::Relationship.association).to eq '-'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should handle a single cardinality' do
|
51
|
+
expect(YUML::Relationship.association('*')).to eq '-*'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should handle a two sided cardinality' do
|
55
|
+
expect(YUML::Relationship.association('1', '*')).to eq '1-*'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#two_way_association' do
|
60
|
+
it 'should return the default two_way_association relationship' do
|
61
|
+
expect(YUML::Relationship.two_way_association).to eq '<->'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should handle a single cardinality' do
|
65
|
+
expect(YUML::Relationship.two_way_association('*')).to eq '<-*>'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should handle a two sided cardinality' do
|
69
|
+
expect(YUML::Relationship.two_way_association('1', '*')).to eq '<1-*>'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#directed_assoication' do
|
74
|
+
it 'should return the default directed_assoication relationship' do
|
75
|
+
expect(YUML::Relationship.directed_assoication).to eq '->'
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should handle a single cardinality' do
|
79
|
+
expect(YUML::Relationship.directed_assoication('*')).to eq '-*>'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should handle a two sided cardinality' do
|
83
|
+
expect(YUML::Relationship.directed_assoication('1', '*')).to eq '1-*>'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#dependency' do
|
88
|
+
it 'should return the default dependency relationship' do
|
89
|
+
expect(YUML::Relationship.dependency).to eq '-.->'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should handle a single cardinality' do
|
93
|
+
expect(YUML::Relationship.dependency('*')).to eq '-.-*>'
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should handle a two sided cardinality' do
|
97
|
+
expect(YUML::Relationship.dependency('1', '*')).to eq '1-.-*>'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/spec/yuml_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/yuml'
|
3
|
+
|
4
|
+
describe YUML do
|
5
|
+
before :all do
|
6
|
+
@doc_uml = "[Document|+foo;+bar|+foo(name#{YUML::ESCAPE_CHARACTERS[',']} other = nil);+bar()]"
|
7
|
+
end
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
@uut = YUML.class do |c|
|
11
|
+
c.name 'Document'
|
12
|
+
c.variables('+foo', '+bar')
|
13
|
+
c.methods('+foo(name, other = nil)', '+bar()')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#class' do
|
18
|
+
it 'should return a YUML::Class' do
|
19
|
+
expect(@uut).to be_an_instance_of YUML::Class
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'it should work when given an arity > 0' do
|
23
|
+
it 'takes a block and builds a YUML::Class' do
|
24
|
+
expect(@uut.to_s).to eq @doc_uml
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'it should work when given with instance_eval' do
|
29
|
+
it 'takes a block and builds a YUML::Class' do
|
30
|
+
doc = YUML.class do
|
31
|
+
name 'Document'
|
32
|
+
variables('+foo', '+bar')
|
33
|
+
methods('+foo(name, other = nil)', '+bar()')
|
34
|
+
end
|
35
|
+
expect(doc.to_s).to eq @doc_uml
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#generate' do
|
41
|
+
include FakeFS::SpecHelpers
|
42
|
+
|
43
|
+
before :all do
|
44
|
+
@options = { file: 'test.pdf' }
|
45
|
+
end
|
46
|
+
|
47
|
+
before :each do
|
48
|
+
@stub = stub_request(:any, %r{http://yuml.me/.*}).to_return(body: 'abc', status: 200)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should yield the block' do
|
52
|
+
expect { |b| YUML.generate(@options, &b) }.to(yield_control.once)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should make the api call' do
|
56
|
+
YUML.generate(@options) do |uml|
|
57
|
+
uml.class do
|
58
|
+
name 'Document'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
expect(@stub).to have_been_requested
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should write the contents to a file' do
|
65
|
+
YUML.generate(@options) do |uml|
|
66
|
+
uml.class do
|
67
|
+
name 'Document'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
expect(File.exist?(@options[:file])).to be true
|
71
|
+
expect(File.read(@options[:file])).to eq 'abc'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yuml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Stride
|
@@ -30,10 +30,18 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
33
36
|
- lib/yuml.rb
|
34
37
|
- lib/yuml/class.rb
|
35
38
|
- lib/yuml/note.rb
|
36
39
|
- lib/yuml/relationship.rb
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- spec/yuml_class_spec.rb
|
42
|
+
- spec/yuml_note_spec.rb
|
43
|
+
- spec/yuml_relationship_spec.rb
|
44
|
+
- spec/yuml_spec.rb
|
37
45
|
homepage: https://github.com/DerekStride/yuml
|
38
46
|
licenses:
|
39
47
|
- MIT
|