diaspora-cluster-creator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p125@diaspora-cluster-creator"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create use "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ if command -v bundle && [[ -s Gemfile ]]
51
+ then
52
+ bundle
53
+ fi
54
+
55
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in diaspora-cluster-creator.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,46 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ notification :growl
5
+
6
+ guard 'minitest', :notify => 'true', :cli => '--color' do
7
+ # with Minitest::Unit
8
+ # watch(%r|^test/(.*)\/?test_(.*)\.rb|)
9
+ # watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
10
+ # watch(%r|^test/test_helper\.rb|) { "test" }
11
+
12
+ # with Minitest::Spec
13
+ watch(%r|^app/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }
14
+ watch(%r|^spec/(.*)_spec\.rb|)
15
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
16
+ watch(%r|^spec/spec_helper\.rb|) { "spec" }
17
+
18
+ # Rails 3.2
19
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
20
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
21
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
22
+
23
+ # Rails
24
+ # watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/functional/#{m[1]}_test.rb" }
25
+ # watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
26
+ # watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
27
+ end
28
+
29
+ # guard 'passenger' do
30
+ # watch(/^lib\/.*\.rb$/)
31
+ # watch(/^config\/.*\.rb$/)
32
+ # end
33
+
34
+ guard 'bundler' do
35
+ watch('Gemfile')
36
+ watch('*.gemspec')
37
+ # Uncomment next line if Gemfile contain `gemspec' command
38
+ # watch(/^.+\.gemspec/)
39
+ end
40
+
41
+ guard 'cucumber' do
42
+ watch(%r{^features/.+\.feature$})
43
+ watch(%r{^features/support/.+$}) { 'features' }
44
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
45
+ watch(%r{^lib/diaspora-cluster-creator/(.+)\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
46
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jeremy Friesen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Diaspora::Cluster::Creator
2
+
3
+ Thus far, this is an over-engineered solution that does very little.
4
+
5
+ I'm using it as a means of pushing out my understanding of cucumber and
6
+ fast unit tests.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'diaspora-cluster-creator'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install diaspora-cluster-creator
21
+
22
+ ## Usage
23
+
24
+
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ require 'cucumber/rake/task'
6
+
7
+ namespace 'test' do |ns|
8
+ test_files = FileList['spec/**/*_spec.rb']
9
+ integration_test_files = FileList['spec/**/*_integration_spec.rb']
10
+ unit_test_files = test_files - integration_test_files
11
+
12
+ desc "Run unit tests"
13
+ Rake::TestTask.new('unit') do |t|
14
+ t.libs.push "lib"
15
+ t.test_files = unit_test_files
16
+ t.verbose = true
17
+ end
18
+
19
+ desc "Run integration tests"
20
+ Rake::TestTask.new('integration') do |t|
21
+ t.libs.push "lib"
22
+ t.test_files = integration_test_files
23
+ t.verbose = true
24
+ end
25
+
26
+ desc "Run acceptance tests"
27
+ Cucumber::Rake::Task.new('acceptance') do |t|
28
+ t.fork = true
29
+ end
30
+ end
31
+
32
+ task('test').clear
33
+ desc "Run all tests"
34
+ task 'test' => %w[test:unit test:integration]
35
+
36
+ task 'default' => %w[test:unit test:integration test:acceptance]
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'main'
4
+ require_relative '../lib/diaspora-cluster-creator'
5
+
6
+ Main do
7
+ description 'Generate a diaspora cluster'
8
+ keyword('names', 'n') {
9
+ arity(-1)
10
+ cast :list_of_string
11
+ description "List of cluster names, comma separated."
12
+ }
13
+ keyword('count', 'c') {
14
+ arity 1
15
+ cast :integer
16
+ description "Instead of a list of names, provide a cluster count."
17
+ }
18
+ keyword('filename', 'f') {
19
+ required
20
+ arity 1
21
+ validate {|output| output =~ /\w\.(png|dot)$/i}
22
+ description "filename.DOT or filename.PNG"
23
+ default "cluster.dot"
24
+ }
25
+ def run
26
+ options = {:names => params[:names].value, :count => params[:count].value, :filename => params[:filename].value}
27
+ Diaspora::Cluster::Creator.run(options)
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/diaspora-cluster-creator/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jeremy Friesen"]
6
+ gem.email = ["jeremy.n.friesen@gmail.com"]
7
+ gem.description = %q{Command-line utility to create Diaspora cluster}
8
+ gem.summary = %q{Command-line utility to create Diaspora cluster}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "diaspora-cluster-creator"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Diaspora::Cluster::Creator::VERSION
17
+ gem.add_development_dependency "cucumber"
18
+ gem.add_development_dependency "bundler"
19
+ gem.add_development_dependency "minitest"
20
+ gem.add_development_dependency "guard"
21
+ gem.add_development_dependency 'guard-minitest'
22
+ gem.add_development_dependency 'guard-bundler'
23
+ gem.add_development_dependency 'guard-cucumber'
24
+ gem.add_development_dependency 'growl'
25
+
26
+ gem.add_runtime_dependency "ruby-graphviz"
27
+ gem.add_runtime_dependency "main"
28
+ gem.add_runtime_dependency "dependency_injector"
29
+ gem.required_rubygems_version = ">= 1.8.7"
30
+ end
@@ -0,0 +1,11 @@
1
+ Feature: Cluster creation
2
+
3
+ Scenario: Cluster creation
4
+ When I request a new cluster with 5 star systems
5
+ Then the output should have 5 nodes
6
+ And the output should have at least 4 edges
7
+
8
+ Scenario: Named systems
9
+ When I create a new cluster with systems "Foo", "Bar", "Baz"
10
+ Then the graph should have nodes "Foo", "Bar", "Baz"
11
+ And the graph should have edges between "Foo", "Bar", "Baz"
@@ -0,0 +1,13 @@
1
+ Feature: Fudge dice
2
+
3
+ Scenario Outline: Rolling fudge dice
4
+ When I roll <Dice>
5
+ Then the result is between <Min> and <Max>
6
+
7
+ Examples:
8
+ | Dice | Min | Max |
9
+ | 1dF | -1 | 1 |
10
+ | 2dF | -2 | 2 |
11
+ | 3dF | -3 | 3 |
12
+ | 4dF | -4 | 4 |
13
+
@@ -0,0 +1,7 @@
1
+ Feature: Star System Creation
2
+
3
+ Scenario: Star System Creation
4
+ When I create a Star System
5
+ Then it should have a technology rating
6
+ And it should have a resources rating
7
+ And it should have a environment rating
@@ -0,0 +1,11 @@
1
+ When /^I request a new cluster with (#{CAPTURE_INTEGER}) star systems?$/ do |count|
2
+ set_current_cluster(['a']*count)
3
+ end
4
+
5
+ Then /^the output should have (#{CAPTURE_INTEGER}) nodes$/ do |count|
6
+ current_graph.nodes.count.must_equal count
7
+ end
8
+
9
+ Then /^the output should have at least (#{CAPTURE_INTEGER}) edges$/ do |count|
10
+ current_graph.edges.count.must_be :>=, count
11
+ end
@@ -0,0 +1,11 @@
1
+ When /^I roll (#{CAPTURE_DICE_TO_ROLL})$/ do |count|
2
+ current_roller.dice_count = count
3
+ end
4
+
5
+ Then /^the result is between (#{CAPTURE_INTEGER}) and (#{CAPTURE_INTEGER})$/ do |arg1, arg2|
6
+ min, max = arg1, arg2
7
+ min, max = arg2, arg1 if min > max
8
+
9
+ current_roller.roll.must_be :>=, min
10
+ current_roller.roll.must_be :<=, max
11
+ end
@@ -0,0 +1,8 @@
1
+ When /^I create a Star System$/ do
2
+ current_star_system
3
+ end
4
+
5
+ Then /^it should have an? (#{CAPTURE_SYSTEM_ATTRIBUTE}) rating$/ do |system_attribute|
6
+ current_star_system.send(system_attribute).must_be :<=, 4
7
+ current_star_system.send(system_attribute).must_be :>=, -4
8
+ end
@@ -0,0 +1,11 @@
1
+ CAPTURE_INTEGER = Transform(/^(-?\d+)$/) { |count|
2
+ count.to_i
3
+ }
4
+
5
+ CAPTURE_DICE_TO_ROLL = Transform(/^(\d+)[d|D]F$/) { |dice_to_roll|
6
+ dice_to_roll.to_i
7
+ }
8
+
9
+ CAPTURE_SYSTEM_ATTRIBUTE = Transform(/^(technology|resources|environment)$/) { |system_attribute_name|
10
+ system_attribute_name
11
+ }
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require_relative '../../lib/diaspora-cluster-creator.rb'
@@ -0,0 +1,3 @@
1
+ require 'minitest/spec'
2
+ World(MiniTest::Assertions)
3
+ MiniTest::Spec.new(nil)
@@ -0,0 +1,23 @@
1
+ module KnowsTheDomain
2
+ include ::Diaspora::Cluster::Creator
3
+ def set_current_cluster(value)
4
+ @current_cluster = Cluster.new(value)
5
+ end
6
+
7
+ def current_cluster
8
+ @current_cluster ||= Cluster.new
9
+ end
10
+
11
+ def current_roller
12
+ @current_roller ||= FateDice.new
13
+ end
14
+
15
+ def current_star_system
16
+ @current_star_system ||= StarSystem.new(current_cluster, 1)
17
+ end
18
+ def current_graph
19
+ @current_graph ||= Graph.new(current_cluster)
20
+ end
21
+ end
22
+
23
+ World(KnowsTheDomain)
@@ -0,0 +1,24 @@
1
+ require_relative "diaspora-cluster-creator/version"
2
+
3
+ module Diaspora
4
+ module Cluster
5
+ module Creator
6
+ def self.run(params)
7
+ names = ('A'..'Z').to_a[0,params[:count] || 6]
8
+ cluster = Cluster.new( params[:names] || names )
9
+ graph = Graph.new(cluster)
10
+ template = Template.new(graph)
11
+ case File.extname(params[:filename])
12
+ when '.dot' then template.to_dot(params[:filename])
13
+ when '.png' then template.to_png(params[:filename])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require_relative "diaspora-cluster-creator/fate_dice"
21
+ require_relative "diaspora-cluster-creator/graph"
22
+ require_relative "diaspora-cluster-creator/cluster"
23
+ require_relative "diaspora-cluster-creator/star_system"
24
+ require_relative "diaspora-cluster-creator/template"
@@ -0,0 +1,41 @@
1
+ require 'dependency_injector'
2
+ require_relative 'star_system'
3
+
4
+ module Diaspora
5
+ module Cluster
6
+ module Creator
7
+ class Cluster
8
+ include Enumerable
9
+ extend DependencyInjector
10
+ def_injector(:star_system_builder) { StarSystem.public_method(:new) }
11
+ def_injector(:star_system_guarantor) { StarSystem.public_method(:guarantee!) }
12
+
13
+ attr_reader :names
14
+
15
+ def initialize(*names)
16
+ @names = names.flatten.compact
17
+ end
18
+
19
+ def each
20
+ star_systems.each {|ss| yield(ss)}
21
+ end
22
+
23
+ def star_systems
24
+ @star_systems ||= build_star_systems
25
+ end
26
+
27
+ def to_s
28
+ 'Cluster'
29
+ end
30
+
31
+ protected
32
+ def build_star_systems
33
+ @star_systems ||= star_system_guarantor.call(generate_first_pass)
34
+ end
35
+ def generate_first_pass
36
+ names.each_with_object([]) {|name,mem| mem << star_system_builder.call(self, name)}
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ require 'dependency_injector'
2
+
3
+ module Diaspora
4
+ module Cluster
5
+ module Creator
6
+ class FateDice
7
+ extend DependencyInjector
8
+ def_injector(:randomizer) { -> { rand(3) - 1 } }
9
+
10
+ attr_reader :dice_count
11
+ def initialize(dice_count = 4)
12
+ self.dice_count = dice_count
13
+ end
14
+
15
+ def roll
16
+ (1..dice_count).inject(0) {|m,v| m += randomizer.call }
17
+ end
18
+
19
+ def dice_count=(value)
20
+ @dice_count = value.to_i
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,58 @@
1
+ require 'dependency_injector'
2
+ require 'set'
3
+ require_relative 'fate_dice'
4
+
5
+ module Diaspora
6
+ module Cluster
7
+ module Creator
8
+ class Graph
9
+ extend DependencyInjector
10
+ def_injector(:dice) { FateDice.new }
11
+
12
+ attr_reader :source
13
+ def initialize(source)
14
+ @source = source
15
+ end
16
+
17
+ def to_s
18
+ source.to_s
19
+ end
20
+
21
+ def nodes
22
+ draw!
23
+ @nodes
24
+ end
25
+
26
+ def edges
27
+ draw!
28
+ @edges
29
+ end
30
+
31
+ private
32
+ def draw!
33
+ return if @__drawn__
34
+ @nodes = source.collect.to_a
35
+ @nodes.each_with_index do |node, i|
36
+ result = dice.roll
37
+ if result < 0
38
+ connect(node, @nodes[i+1])
39
+ elsif result == 0
40
+ connect(node, @nodes[i+1], @nodes[i+2])
41
+ elsif result > 0
42
+ connect(node, @nodes[i+1], @nodes[i+2], @nodes[i+3])
43
+ end
44
+ end
45
+ @__drawn__ = true
46
+ end
47
+
48
+ def connect(node, *others)
49
+ @edges ||= Set.new
50
+
51
+ others.flatten.compact.each do |other|
52
+ @edges << [node,other]
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,65 @@
1
+ require 'dependency_injector'
2
+ require 'set'
3
+ require_relative 'fate_dice'
4
+
5
+ module Diaspora
6
+ module Cluster
7
+ module Creator
8
+ class StarSystem
9
+ def self.rolled_attributes
10
+ unless defined?(@@rolled_attributes)
11
+ @@rolled_attributes = Set.new
12
+ end
13
+ @@rolled_attributes
14
+ end
15
+ def self.rolled_attribute(attribute_name)
16
+ rolled_attributes << attribute_name
17
+ define_method(attribute_name) do
18
+ instance_variable_get("@#{attribute_name}") || instance_variable_set("@#{attribute_name}", dice.roll)
19
+ instance_variable_get("@#{attribute_name}")
20
+ end
21
+ define_method("#{attribute_name}=") do |value|
22
+ instance_variable_set("@#{attribute_name}", value.to_i)
23
+ end
24
+ end
25
+ def self.guarantee!(star_systems)
26
+ return star_systems if star_systems.detect {|ss| ss.technology >= 2 }
27
+ working = star_systems.sort
28
+ working.first.technology = 2
29
+ working.last.technology = 2
30
+ star_systems
31
+ end
32
+
33
+ extend DependencyInjector
34
+ def_injector(:dice) { FateDice.new }
35
+
36
+ attr_reader :context, :name
37
+ def initialize(context, name)
38
+ @context = context
39
+ @name = name
40
+ end
41
+
42
+ rolled_attribute :technology
43
+ rolled_attribute :resources
44
+ rolled_attribute :environment
45
+
46
+ include Comparable
47
+ def <=>(other)
48
+ to_i <=> other.to_i
49
+ end
50
+
51
+ def to_i
52
+ self.class.rolled_attributes.inject(0) {|m,v| m += send(v) }
53
+ end
54
+
55
+ def to_s
56
+ name.to_s
57
+ end
58
+
59
+ def label
60
+ "#{name}\nT#{technology} R#{resources} E#{environment}"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,40 @@
1
+ require 'graphviz'
2
+ module Diaspora
3
+ module Cluster
4
+ module Creator
5
+ class Template
6
+ attr_reader :graph
7
+ def initialize(graph)
8
+ raise RuntimeError unless graph.respond_to?(:nodes)
9
+ raise RuntimeError unless graph.respond_to?(:edges)
10
+ @graph = graph
11
+ end
12
+ def to_s
13
+ canvas.to_s
14
+ end
15
+ def to_dot(filename = 'graph.dot')
16
+ canvas.output(:dot => "#{filename}")
17
+ end
18
+ def to_png(filename = 'graph.png')
19
+ canvas.output(:png => "#{filename}")
20
+ end
21
+ protected
22
+ def canvas
23
+ template = GraphViz.new(graph.to_s, :type => :graph )
24
+ nodes = {}
25
+ graph.nodes.each do |node|
26
+ nodes[node] = template.add_nodes(node.to_s, :label => (node.respond_to?(:label) ? node.label : node.to_s))
27
+ end
28
+
29
+ graph.edges.each do |edge|
30
+ to = edge[0]
31
+ from = edge[1]
32
+ template.add_edges(to.to_s, from.to_s)
33
+ end
34
+
35
+ template
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ module Diaspora
2
+ module Cluster
3
+ module Creator
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../spec_helper_lite'
2
+ require 'cluster'
3
+
4
+ describe Cluster do
5
+ subject { Cluster.new(names) }
6
+ let(:names) { ['a'] }
7
+
8
+ describe '#each' do
9
+ it 'should yield built star system' do
10
+ built_object = Object.new
11
+ transformed_object = Object.new
12
+ guarantor = MiniTest::Mock.new
13
+ builder = MiniTest::Mock.new
14
+ builder.expect(:call, built_object, [subject,'a'])
15
+ guarantor.expect(:call, [transformed_object], [[built_object]])
16
+
17
+ subject.star_system_builder = builder
18
+ subject.star_system_guarantor = guarantor
19
+ @yielded = []
20
+ subject.each {|object| @yielded << object }
21
+ builder.verify
22
+ guarantor.verify
23
+ @yielded.must_equal [transformed_object]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../spec_helper_lite'
2
+ require 'fate_dice'
3
+
4
+ describe FateDice do
5
+ subject { FateDice.new }
6
+
7
+ describe '#roll' do
8
+ it 'should be the sum of 4 Fudge dice' do
9
+ loaded_dice = MiniTest::Mock.new
10
+ loaded_dice.expect(:call, 1)
11
+ subject.randomizer = loaded_dice
12
+ subject.roll.must_equal 4
13
+ loaded_dice.verify
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ require_relative '../spec_helper_lite'
2
+ require 'graph'
3
+
4
+ describe Graph do
5
+ subject { Graph.new(collection) }
6
+ let(:collection) {[1,2,3]}
7
+
8
+ describe '#nodes' do
9
+ it 'should be the collection of the input' do
10
+ subject.nodes.must_equal collection
11
+ end
12
+ end
13
+
14
+ describe '#edges' do
15
+ it 'connection for all -1 rolls' do
16
+ expected = Set.new
17
+ expected << [1,2]
18
+ expected << [2,3]
19
+ with_loaded_dice(-1, subject) do
20
+ subject.edges.must_equal expected
21
+ end
22
+ end
23
+
24
+ it 'connection for all -2 rolls' do
25
+ expected = Set.new
26
+ expected << [1,2]
27
+ expected << [1,3]
28
+ expected << [2,3]
29
+ with_loaded_dice(0, subject) do
30
+ subject.edges.must_equal expected
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,89 @@
1
+ require_relative '../spec_helper_lite'
2
+ require 'star_system'
3
+
4
+ describe StarSystem do
5
+ subject { StarSystem.new( Object.new, 1 ) }
6
+
7
+ describe '#technology=' do
8
+ it 'should be overridable' do
9
+ subject.technology = 3
10
+ subject.technology.must_equal 3
11
+ end
12
+ end
13
+
14
+ describe '#technology' do
15
+ it 'should be randomly rolled' do
16
+ with_loaded_dice(1, subject) do
17
+ subject.technology.must_equal 1
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '#resources' do
23
+ it 'should be randomly rolled' do
24
+ with_loaded_dice(1, subject) do
25
+ subject.resources.must_equal 1
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#environment' do
31
+ it 'should be randomly rolled' do
32
+ with_loaded_dice(1, subject) do
33
+ subject.environment.must_equal 1
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '#<=>' do
39
+ it 'should be comparable to another star system' do
40
+ @system_a = StarSystem.new('', 1)
41
+ @system_b = StarSystem.new('', 2)
42
+ with_loaded_dice(2, @system_a) do
43
+ with_loaded_dice(1, @system_b) do
44
+ @system_b.must_be :<, @system_a
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '.guarantee!' do
51
+ it 'should adjust technology rating without altering the sort order' do
52
+ @system_a = StarSystem.new('', 1)
53
+ @system_b = StarSystem.new('', 2)
54
+ @system_c = StarSystem.new('', 3)
55
+ order =
56
+ with_loaded_dice(1, @system_a) do
57
+ with_loaded_dice(0, @system_b) do
58
+ with_loaded_dice(-1, @system_c) do
59
+ input = [@system_b, @system_c, @system_a]
60
+ StarSystem.guarantee!(input).must_equal input
61
+ end
62
+ end
63
+ end
64
+
65
+ @system_a.technology.must_equal 2
66
+ @system_b.technology.must_equal 0
67
+ @system_c.technology.must_equal 2
68
+ end
69
+
70
+ it 'should not adjust technology rating if one is already adequate' do
71
+ @system_a = StarSystem.new('', 1)
72
+ @system_b = StarSystem.new('', 2)
73
+ @system_c = StarSystem.new('', 3)
74
+ order =
75
+ with_loaded_dice(2, @system_a) do
76
+ with_loaded_dice(0, @system_b) do
77
+ with_loaded_dice(-1, @system_c) do
78
+ input = [@system_b, @system_c, @system_a]
79
+ StarSystem.guarantee!(input).must_equal input
80
+ end
81
+ end
82
+ end
83
+
84
+ @system_a.technology.must_equal 2
85
+ @system_b.technology.must_equal 0
86
+ @system_c.technology.must_equal(-1)
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../spec_helper_lite'
2
+ require 'template'
3
+
4
+ describe Template do
5
+ describe '#to_dot' do
6
+ it 'should remder star systems and their connections' do
7
+ @names = ["Hello", "World", "Foo", "Bar"]
8
+ @cluster = Cluster.new(@names)
9
+ @graph = Graph.new(@cluster)
10
+ @template = Template.new(@graph)
11
+ @template.to_s.tap do |dot|
12
+ @cluster.each do |system|
13
+ dot.must_include(%([label = #{system.label.inspect}]))
14
+ end
15
+ @graph.edges.each do |edge|
16
+ dot.must_match(/"?#{edge.first}"? -- "?#{edge.last}"?/)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ require_relative '../spec_helper_lite'
2
+ require 'template'
3
+
4
+ describe Template do
5
+ subject { Template.new(graph) }
6
+ let(:graph) {
7
+ object = Object.new
8
+ def object.edges; [['a','b'],['a','c']]; end
9
+ def object.nodes; ['a','b','c']; end
10
+ def object.to_s; "Custom Name"; end
11
+ object
12
+ }
13
+
14
+ describe '#to_s' do
15
+ it 'should render pretty' do
16
+ subject.to_s.must_equal(
17
+ [
18
+ %(graph #{graph.to_s.inspect} {),
19
+ %( a [label = "a"];),
20
+ %( b [label = "b"];),
21
+ %( c [label = "c"];),
22
+ %( a -- b),
23
+ %( a -- c),
24
+ %(})
25
+ ].join("\n")
26
+ )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ gem 'minitest' # demand gem version
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'ostruct'
5
+ $: << File.expand_path('../lib/diaspora-cluster-creator', File.dirname(__FILE__))
6
+ require 'diaspora-cluster-creator'
7
+
8
+ # Cheating a bit to help tests be a bit more readable
9
+ include Diaspora::Cluster::Creator
10
+
11
+ class MiniTest::Unit::TestCase
12
+ def with_loaded_dice(roll, object)
13
+ loaded_dice = MiniTest::Mock.new
14
+ loaded_dice.expect(:roll, roll)
15
+ object.dice = loaded_dice
16
+ yield
17
+ loaded_dice.verify
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diaspora-cluster-creator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Friesen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cucumber
16
+ requirement: &2156617540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2156617540
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2156617120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2156617120
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &2156616680 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2156616680
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard
49
+ requirement: &2156616040 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2156616040
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-minitest
60
+ requirement: &2156615380 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2156615380
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-bundler
71
+ requirement: &2156614900 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2156614900
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-cucumber
82
+ requirement: &2156614460 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2156614460
91
+ - !ruby/object:Gem::Dependency
92
+ name: growl
93
+ requirement: &2156613960 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2156613960
102
+ - !ruby/object:Gem::Dependency
103
+ name: ruby-graphviz
104
+ requirement: &2156613480 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: *2156613480
113
+ - !ruby/object:Gem::Dependency
114
+ name: main
115
+ requirement: &2156613040 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: *2156613040
124
+ - !ruby/object:Gem::Dependency
125
+ name: dependency_injector
126
+ requirement: &2156612580 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: *2156612580
135
+ description: Command-line utility to create Diaspora cluster
136
+ email:
137
+ - jeremy.n.friesen@gmail.com
138
+ executables:
139
+ - diaspora-cluster
140
+ extensions: []
141
+ extra_rdoc_files: []
142
+ files:
143
+ - .gitignore
144
+ - .rvmrc
145
+ - Gemfile
146
+ - Guardfile
147
+ - LICENSE
148
+ - README.md
149
+ - Rakefile
150
+ - bin/diaspora-cluster
151
+ - diaspora-cluster-creator.gemspec
152
+ - features/cluster.feature
153
+ - features/fate_dice.feature
154
+ - features/star_system.feature
155
+ - features/step_definitions/cluster_steps.rb
156
+ - features/step_definitions/fate_dice_steps.rb
157
+ - features/step_definitions/star_system_steps.rb
158
+ - features/support/captures.rb
159
+ - features/support/env.rb
160
+ - features/support/minitest.rb
161
+ - features/support/world.rb
162
+ - lib/diaspora-cluster-creator.rb
163
+ - lib/diaspora-cluster-creator/cluster.rb
164
+ - lib/diaspora-cluster-creator/fate_dice.rb
165
+ - lib/diaspora-cluster-creator/graph.rb
166
+ - lib/diaspora-cluster-creator/star_system.rb
167
+ - lib/diaspora-cluster-creator/template.rb
168
+ - lib/diaspora-cluster-creator/version.rb
169
+ - spec/diaspora-cluster-creator/cluster_spec.rb
170
+ - spec/diaspora-cluster-creator/fate_dice_spec.rb
171
+ - spec/diaspora-cluster-creator/graph_spec.rb
172
+ - spec/diaspora-cluster-creator/star_system_spec.rb
173
+ - spec/diaspora-cluster-creator/template_integration_spec.rb
174
+ - spec/diaspora-cluster-creator/template_spec.rb
175
+ - spec/spec_helper_lite.rb
176
+ homepage: ''
177
+ licenses: []
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: 1.8.7
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 1.8.17
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: Command-line utility to create Diaspora cluster
200
+ test_files:
201
+ - features/cluster.feature
202
+ - features/fate_dice.feature
203
+ - features/star_system.feature
204
+ - features/step_definitions/cluster_steps.rb
205
+ - features/step_definitions/fate_dice_steps.rb
206
+ - features/step_definitions/star_system_steps.rb
207
+ - features/support/captures.rb
208
+ - features/support/env.rb
209
+ - features/support/minitest.rb
210
+ - features/support/world.rb
211
+ - spec/diaspora-cluster-creator/cluster_spec.rb
212
+ - spec/diaspora-cluster-creator/fate_dice_spec.rb
213
+ - spec/diaspora-cluster-creator/graph_spec.rb
214
+ - spec/diaspora-cluster-creator/star_system_spec.rb
215
+ - spec/diaspora-cluster-creator/template_integration_spec.rb
216
+ - spec/diaspora-cluster-creator/template_spec.rb
217
+ - spec/spec_helper_lite.rb