ul-wukong 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +60 -0
- data/.gitmodules +6 -0
- data/.rspec +2 -0
- data/.travis.yml +19 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +17 -0
- data/Guardfile +12 -0
- data/LICENSE.md +95 -0
- data/NOTES-travis.md +31 -0
- data/README-old.md +422 -0
- data/README.md +1308 -0
- data/Rakefile +28 -0
- data/TODO.md +99 -0
- data/bin/cutc +30 -0
- data/bin/cuttab +5 -0
- data/bin/greptrue +6 -0
- data/bin/md5sort +20 -0
- data/bin/setcat +11 -0
- data/bin/tabchar +5 -0
- data/bin/uniq-ord +59 -0
- data/bin/uniqc +3 -0
- data/bin/wu +34 -0
- data/bin/wu-clean-encoding +31 -0
- data/bin/wu-date +13 -0
- data/bin/wu-datetime +13 -0
- data/bin/wu-hist +3 -0
- data/bin/wu-lign +186 -0
- data/bin/wu-local +4 -0
- data/bin/wu-plus +9 -0
- data/bin/wu-source +5 -0
- data/bin/wu-sum +31 -0
- data/diagrams/wu_local.dot +39 -0
- data/diagrams/wu_local.dot.png +0 -0
- data/examples/Gemfile +38 -0
- data/examples/README.md +9 -0
- data/examples/basic/string_reverser.rb +23 -0
- data/examples/basic/tiny_count.rb +8 -0
- data/examples/basic/word_count/accumulator.rb +26 -0
- data/examples/basic/word_count/tokenizer.rb +13 -0
- data/examples/basic/word_count/word_count.rb +6 -0
- data/examples/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/deploy_pack/Gemfile +6 -0
- data/examples/deploy_pack/README.md +6 -0
- data/examples/deploy_pack/a/b/c/.gitkeep +0 -0
- data/examples/deploy_pack/app/processors/string_reverser.rb +5 -0
- data/examples/deploy_pack/config/environment.rb +1 -0
- data/examples/dsl/dataflow/fibonacci_series.rb +101 -0
- data/examples/dsl/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/dsl/dataflow/simple.rb +12 -0
- data/examples/dsl/dataflow/telegram.rb +45 -0
- data/examples/dsl/workflow/cherry_pie.dot +97 -0
- data/examples/dsl/workflow/cherry_pie.md +104 -0
- data/examples/dsl/workflow/cherry_pie.png +0 -0
- data/examples/dsl/workflow/cherry_pie.rb +101 -0
- data/examples/empty/.gitkeep +0 -0
- data/examples/examples_helper.rb +9 -0
- data/examples/geo.rb +4 -0
- data/examples/geo/geo_grids.numbers +0 -0
- data/examples/geo/geolocated.rb +331 -0
- data/examples/geo/quadtile.rb +69 -0
- data/examples/geo/spec/geolocated_spec.rb +247 -0
- data/examples/geo/tile_fetcher.rb +77 -0
- data/examples/graph/implied_geolocation/README.md +63 -0
- data/examples/graph/minimum_spanning_tree/airfares_graphviz.rb +73 -0
- data/examples/improver/tweet_summary.rb +73 -0
- data/examples/loadable.rb +2 -0
- data/examples/munging/airline_flights/airline_flights.rake +83 -0
- data/examples/munging/airline_flights/airplane.rb +0 -0
- data/examples/munging/airline_flights/airport_id_unification.rb +129 -0
- data/examples/munging/airline_flights/airport_ok_chars.rb +4 -0
- data/examples/munging/airline_flights/indexable.rb +75 -0
- data/examples/munging/airline_flights/indexable_spec.rb +90 -0
- data/examples/munging/airline_flights/reconcile_airports.rb +142 -0
- data/examples/munging/airline_flights/tasks.rake +83 -0
- data/examples/munging/airline_flights/topcities.rb +167 -0
- data/examples/munging/geo/geo_json.rb +54 -0
- data/examples/munging/geo/geo_models.rb +69 -0
- data/examples/munging/geo/geonames_models.rb +107 -0
- data/examples/munging/geo/iso_codes.rb +172 -0
- data/examples/munging/geo/reconcile_countries.rb +124 -0
- data/examples/munging/geo/tasks.rake +71 -0
- data/examples/munging/wikipedia/articles/extract_articles-parsed.rb +79 -0
- data/examples/munging/wikipedia/articles/extract_articles-templated.rb +136 -0
- data/examples/munging/wikipedia/articles/textualize_articles.rb +54 -0
- data/examples/munging/wikipedia/articles/verify_structure.rb +43 -0
- data/examples/munging/wikipedia/articles/wp2txt-LICENSE.txt +22 -0
- data/examples/munging/wikipedia/articles/wp2txt_article.rb +259 -0
- data/examples/munging/wikipedia/articles/wp2txt_utils.rb +452 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_common.rb +5 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_extract_geocoordinates.rb +78 -0
- data/examples/munging/wikipedia/dbpedia/extract_links-cruft.rb +66 -0
- data/examples/munging/wikipedia/dbpedia/extract_links.rb +260 -0
- data/examples/munging/wikipedia/dbpedia/sameas_extractor.rb +20 -0
- data/examples/rake_helper.rb +97 -0
- data/examples/ruby_project/Gemfile +6 -0
- data/examples/ruby_project/README.md +6 -0
- data/examples/ruby_project/a/b/c/.gitkeep +0 -0
- data/examples/server_logs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/server_logs/logline.rb +95 -0
- data/examples/server_logs/models.rb +66 -0
- data/examples/server_logs/page_counts.pig +48 -0
- data/examples/server_logs/server_logs-01-parse-script.rb +13 -0
- data/examples/server_logs/server_logs-02-histograms-full.rb +33 -0
- data/examples/server_logs/server_logs-02-histograms-mapper.rb +14 -0
- data/examples/server_logs/server_logs-03-breadcrumbs-full.rb +71 -0
- data/examples/server_logs/server_logs-04-page_page_edges-full.rb +40 -0
- data/examples/serverlogs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/serverlogs/models/logline.rb +102 -0
- data/examples/serverlogs/parser/apache_parser_widget.rb +46 -0
- data/examples/serverlogs/visit_paths/common.rb +4 -0
- data/examples/serverlogs/visit_paths/page_counts.pig +48 -0
- data/examples/serverlogs/visit_paths/serverlogs-01-parse-script.rb +11 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-full.rb +31 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-mapper.rb +12 -0
- data/examples/serverlogs/visit_paths/serverlogs-03-breadcrumbs-full.rb +67 -0
- data/examples/serverlogs/visit_paths/serverlogs-04-page_page_edges-full.rb +38 -0
- data/examples/splitter.rb +94 -0
- data/examples/string_reverser.rb +7 -0
- data/examples/text/pig_latin/pig_latinizer.rb +35 -0
- data/examples/text/pig_latin/pig_latinizer_widget.rb +16 -0
- data/examples/text/regional_flavor/README.md +14 -0
- data/examples/text/regional_flavor/article_wordbags.pig +39 -0
- data/examples/text/regional_flavor/j01-article_wordbags.rb +4 -0
- data/examples/text/regional_flavor/simple_pig_script.pig +27 -0
- data/examples/twitter.rb +5 -0
- data/lib/hanuman.rb +36 -0
- data/lib/hanuman/graph.rb +97 -0
- data/lib/hanuman/graphvizzer.rb +206 -0
- data/lib/hanuman/graphvizzer/gv_models.rb +161 -0
- data/lib/hanuman/graphvizzer/gv_presenter.rb +97 -0
- data/lib/hanuman/link.rb +35 -0
- data/lib/hanuman/registry.rb +46 -0
- data/lib/hanuman/stage.rb +128 -0
- data/lib/hanuman/tree.rb +67 -0
- data/lib/wu/geo.rb +4 -0
- data/lib/wu/geo/geo_grids.numbers +0 -0
- data/lib/wu/geo/geolocated.rb +331 -0
- data/lib/wu/geo/quadtile.rb +69 -0
- data/lib/wu/graph/union_find.rb +62 -0
- data/lib/wu/model/reconcilable.rb +63 -0
- data/lib/wu/munging.rb +71 -0
- data/lib/wu/social/models/twitter.rb +31 -0
- data/lib/wu/wikipedia/models.rb +20 -0
- data/lib/wukong.rb +54 -0
- data/lib/wukong/dataflow.rb +43 -0
- data/lib/wukong/doc_helpers.rb +14 -0
- data/lib/wukong/doc_helpers/dataflow_handler.rb +29 -0
- data/lib/wukong/doc_helpers/field_handler.rb +91 -0
- data/lib/wukong/doc_helpers/processor_handler.rb +29 -0
- data/lib/wukong/driver.rb +214 -0
- data/lib/wukong/driver/event_machine_driver.rb +15 -0
- data/lib/wukong/driver/wiring.rb +68 -0
- data/lib/wukong/local.rb +42 -0
- data/lib/wukong/local/runner.rb +96 -0
- data/lib/wukong/local/stdio_driver.rb +104 -0
- data/lib/wukong/logger.rb +102 -0
- data/lib/wukong/model/faker.rb +136 -0
- data/lib/wukong/model/flatpack_parser/flat.rb +60 -0
- data/lib/wukong/model/flatpack_parser/flatpack.rb +4 -0
- data/lib/wukong/model/flatpack_parser/lang.rb +46 -0
- data/lib/wukong/model/flatpack_parser/parser.rb +55 -0
- data/lib/wukong/model/flatpack_parser/tokens.rb +130 -0
- data/lib/wukong/plugin.rb +48 -0
- data/lib/wukong/processor.rb +110 -0
- data/lib/wukong/rake_helper.rb +6 -0
- data/lib/wukong/runner.rb +169 -0
- data/lib/wukong/runner/boot_sequence.rb +123 -0
- data/lib/wukong/runner/code_loader.rb +52 -0
- data/lib/wukong/runner/command_runner.rb +44 -0
- data/lib/wukong/runner/deploy_pack_loader.rb +75 -0
- data/lib/wukong/runner/help_message.rb +42 -0
- data/lib/wukong/source.rb +33 -0
- data/lib/wukong/source/source_driver.rb +74 -0
- data/lib/wukong/source/source_runner.rb +38 -0
- data/lib/wukong/spec_helpers.rb +74 -0
- data/lib/wukong/spec_helpers/integration_tests.rb +150 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb +207 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb +97 -0
- data/lib/wukong/spec_helpers/shared_examples.rb +22 -0
- data/lib/wukong/spec_helpers/unit_tests.rb +135 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb +132 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb +169 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_runner.rb +60 -0
- data/lib/wukong/version.rb +3 -0
- data/lib/wukong/widget/echo.rb +55 -0
- data/lib/wukong/widget/extract.rb +122 -0
- data/lib/wukong/widget/filters.rb +452 -0
- data/lib/wukong/widget/logger.rb +56 -0
- data/lib/wukong/widget/operators.rb +82 -0
- data/lib/wukong/widget/reducers.rb +10 -0
- data/lib/wukong/widget/reducers/accumulator.rb +73 -0
- data/lib/wukong/widget/reducers/bin.rb +368 -0
- data/lib/wukong/widget/reducers/count.rb +73 -0
- data/lib/wukong/widget/reducers/group.rb +128 -0
- data/lib/wukong/widget/reducers/group_concat.rb +98 -0
- data/lib/wukong/widget/reducers/improver.rb +71 -0
- data/lib/wukong/widget/reducers/join_xml.rb +37 -0
- data/lib/wukong/widget/reducers/moments.rb +72 -0
- data/lib/wukong/widget/reducers/sort.rb +180 -0
- data/lib/wukong/widget/reducers/uniq.rb +91 -0
- data/lib/wukong/widget/serializers.rb +317 -0
- data/lib/wukong/widget/utils.rb +46 -0
- data/lib/wukong/widgets.rb +7 -0
- data/spec/examples/dataflow/fibonacci_series_spec.rb +18 -0
- data/spec/examples/dataflow/parse_apache_logs_spec.rb +8 -0
- data/spec/examples/dataflow/parsing_spec.rb +14 -0
- data/spec/examples/dataflow/simple_spec.rb +34 -0
- data/spec/examples/dataflow/telegram_spec.rb +43 -0
- data/spec/examples/graph/minimum_spanning_tree_spec.rb +34 -0
- data/spec/examples/munging/airline_flights/identifiers_spec.rb +16 -0
- data/spec/examples/munging/airline_flights_spec.rb +202 -0
- data/spec/examples/text/pig_latin_spec.rb +18 -0
- data/spec/examples/workflow/cherry_pie_spec.rb +36 -0
- data/spec/hanuman/graph_spec.rb +119 -0
- data/spec/hanuman/hanuman_spec.rb +10 -0
- data/spec/hanuman/registry_spec.rb +123 -0
- data/spec/hanuman/stage_spec.rb +81 -0
- data/spec/hanuman/tree_spec.rb +119 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/example_test_helpers.rb +95 -0
- data/spec/support/hanuman_test_helpers.rb +92 -0
- data/spec/support/integration_helper.rb +38 -0
- data/spec/support/model_test_helpers.rb +115 -0
- data/spec/support/shared_context_for_graphs.rb +57 -0
- data/spec/support/shared_context_for_reducers.rb +37 -0
- data/spec/support/shared_examples_for_builders.rb +94 -0
- data/spec/support/shared_examples_for_shortcuts.rb +57 -0
- data/spec/wu/model/reconcilable_spec.rb +152 -0
- data/spec/wukong/dataflow_spec.rb +87 -0
- data/spec/wukong/driver_spec.rb +154 -0
- data/spec/wukong/local/runner_spec.rb +29 -0
- data/spec/wukong/local/stdio_driver_spec.rb +73 -0
- data/spec/wukong/local_spec.rb +6 -0
- data/spec/wukong/logger_spec.rb +49 -0
- data/spec/wukong/model/faker_spec.rb +132 -0
- data/spec/wukong/processor_spec.rb +21 -0
- data/spec/wukong/runner_spec.rb +132 -0
- data/spec/wukong/source_spec.rb +6 -0
- data/spec/wukong/widget/extract_spec.rb +101 -0
- data/spec/wukong/widget/filters_spec.rb +79 -0
- data/spec/wukong/widget/logger_spec.rb +23 -0
- data/spec/wukong/widget/operators_spec.rb +25 -0
- data/spec/wukong/widget/reducers/bin_spec.rb +92 -0
- data/spec/wukong/widget/reducers/count_spec.rb +11 -0
- data/spec/wukong/widget/reducers/group_spec.rb +21 -0
- data/spec/wukong/widget/reducers/join_xml_spec.rb +25 -0
- data/spec/wukong/widget/reducers/moments_spec.rb +36 -0
- data/spec/wukong/widget/reducers/sort_spec.rb +26 -0
- data/spec/wukong/widget/reducers/uniq_spec.rb +14 -0
- data/spec/wukong/widget/serializers_spec.rb +114 -0
- data/spec/wukong/widget/sink_spec.rb +19 -0
- data/spec/wukong/widget/source_spec.rb +65 -0
- data/spec/wukong/wu-local_spec.rb +109 -0
- data/spec/wukong/wu-source_spec.rb +32 -0
- data/spec/wukong/wu_spec.rb +14 -0
- data/spec/wukong/wukong_spec.rb +10 -0
- data/wukong.gemspec +35 -0
- metadata +465 -0
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'wukong'
|
2
|
+
require 'wukong/spec_helpers'
|
3
|
+
require 'wukong/source'
|
4
|
+
require_relative './support/shared_context_for_graphs'
|
5
|
+
require_relative './support/shared_examples_for_shortcuts'
|
6
|
+
require_relative './support/shared_examples_for_builders'
|
7
|
+
require_relative './support/shared_context_for_reducers'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
|
11
|
+
config.mock_with :rspec
|
12
|
+
|
13
|
+
include Wukong::SpecHelpers
|
14
|
+
def root
|
15
|
+
@root ||= Pathname.new(File.expand_path('../..', __FILE__))
|
16
|
+
end
|
17
|
+
|
18
|
+
def local_runner *args
|
19
|
+
runner(Wukong::Local::LocalRunner, 'wu-local', *args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def generic_runner *args
|
23
|
+
# the wu-generic program doesn't have to exist for this Runner to
|
24
|
+
# work if it's called from Ruby code
|
25
|
+
runner(Wukong::Runner, 'wu-generic', *args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def wu_local *args
|
29
|
+
command('wu-local', *args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def wu_source *args
|
33
|
+
command('wu-source', *args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def wu *args
|
37
|
+
command('wu', *args)
|
38
|
+
end
|
39
|
+
|
40
|
+
# FIXME Why is this here?
|
41
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
if ENV['WUKONG_COV']
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter '/gorillib/'
|
5
|
+
add_filter '/away/'
|
6
|
+
add_group 'Hanuman', '/hanuman/'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'gorillib/pathname'
|
11
|
+
require 'gorillib/type/extended'
|
12
|
+
require 'wukong/model/faker'
|
13
|
+
|
14
|
+
Pathname.register_path(:wukong_root, File.expand_path('..', File.dirname(__FILE__)))
|
15
|
+
Pathname.register_path(:examples, :wukong_root, 'examples')
|
16
|
+
Pathname.register_path(:tmp, :wukong_root, 'tmp')
|
17
|
+
Pathname.register_path(:data, :wukong_root, 'data')
|
18
|
+
Pathname.path_to(:tmp).mkpath
|
19
|
+
|
20
|
+
Dir[ Pathname.path_to('spec', 'support', '*.rb') ].each{|f| require f }
|
21
|
+
|
22
|
+
result = `dot -V 2>&1` rescue nil
|
23
|
+
GRAPHVIZ = ($?.exitstatus == 0) && (result =~ /dot - graphviz version/)
|
24
|
+
puts 'Some specs require graphviz to run -- brew/apt install graphviz, it is pretty awesome' unless GRAPHVIZ
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
28
|
+
end
|
29
|
+
|
30
|
+
shared_context 'wukong', :helpers => true do
|
31
|
+
RSpec::Matchers.define(:be_in){|expected| match{|actual| expected.include?(actual) } }
|
32
|
+
|
33
|
+
def self.be_ish_matcher(handle, regexp)
|
34
|
+
RSpec::Matchers.define("be_#{handle}_ish"){ match{|actual| actual.should =~ regexp } }
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:mock_val) { mock('mock val') }
|
38
|
+
let(:mock_record) { mock('mock record') }
|
39
|
+
let(:mock_stage) { mock('mock stage') }
|
40
|
+
let(:mock_processor){ mock('mock processor') }
|
41
|
+
|
42
|
+
let(:test_source) { Wukong::Integers.new(:name => :integers, :qty => 100) }
|
43
|
+
let(:test_sink) { Wukong::Sink::ArraySink.new(:name => :test_sink) }
|
44
|
+
let(:test_processor_class){ Wukong::AsIs }
|
45
|
+
let(:test_processor) { test_processor_class.new }
|
46
|
+
let(:test_filter) { Wukong::Widget::RegexpFilter.new(:re => /^m/) }
|
47
|
+
let(:test_dataflow) { Wukong.dataflow(:test_dataflow) }
|
48
|
+
end
|
49
|
+
|
50
|
+
require 'gorillib/utils/capture_output'
|
51
|
+
|
52
|
+
module WukongTestHelpers
|
53
|
+
|
54
|
+
def example_script_filename(name)
|
55
|
+
Pathname.path_to(:examples, name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def example_script_contents(name)
|
59
|
+
File.read(example_script_filename(name))
|
60
|
+
end
|
61
|
+
|
62
|
+
def sample_data_filename(name)
|
63
|
+
Pathname.path_to(:wukong_root, 'data', name)
|
64
|
+
end
|
65
|
+
|
66
|
+
def sample_data(name)
|
67
|
+
File.open(sample_data_filename(name))
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
RSpec::Core::DSL.module_eval do
|
73
|
+
def describe_example_script(example_name, source_file, attrs={}, &block)
|
74
|
+
return unless attrs[:only]
|
75
|
+
load Pathname.path_to(:examples, source_file)
|
76
|
+
describe "Example: #{example_name}", attrs.merge(:examples_spec => true, :helpers => true) do
|
77
|
+
let(:example_name){ example_name }
|
78
|
+
instance_eval(&block)
|
79
|
+
end
|
80
|
+
rescue StandardError => err
|
81
|
+
warn "Broken example #{example_name} with script #{source_file} (#{attrs})"
|
82
|
+
warn err
|
83
|
+
warn err.backtrace.join("\n")
|
84
|
+
end
|
85
|
+
|
86
|
+
def it_generates_graphviz
|
87
|
+
it 'generates a graphviz picture', :if => GRAPHVIZ do
|
88
|
+
require 'hanuman/graphvizzer/gv_presenter'
|
89
|
+
#
|
90
|
+
basename = Pathname.path_to(:tmp, example_name.to_s)
|
91
|
+
Wukong.to_graphviz.save(basename, 'png')
|
92
|
+
yield "#{basename}.dot" if block_given?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'gorillib/utils/capture_output'
|
2
|
+
|
3
|
+
shared_context 'hanuman', :helpers => true do
|
4
|
+
let(:test_stage){ Hanuman::Stage.new(:name => :testy) }
|
5
|
+
|
6
|
+
let :example_graph do
|
7
|
+
Hanuman::Graph.new(:name => :scraper) do
|
8
|
+
action(:listener) << product(:scrape_requests) << product(:more_requests)
|
9
|
+
action(:parser).input(:listener)
|
10
|
+
action(:models).input(:parser)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
shared_examples_for 'it can be linked into' do
|
17
|
+
let(:mock_slot){ mock('mock slot') }
|
18
|
+
before do
|
19
|
+
mock_dataflow.stub(:connect).with(mock_slot, :default, subject, :default).and_return([mock_slot, subject])
|
20
|
+
subject.write_attribute(:owner, mock_dataflow)
|
21
|
+
end
|
22
|
+
|
23
|
+
context '#<<' do
|
24
|
+
it 'delegates to from' do
|
25
|
+
subject.should_receive(:from).with(mock_slot)
|
26
|
+
subject << mock_slot
|
27
|
+
end
|
28
|
+
it 'returns the stage itself, for chaining' do
|
29
|
+
(subject << mock_slot).should == subject
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context '#from' do
|
34
|
+
it 'asks its owner to register an edge from self into given stage' do
|
35
|
+
mock_dataflow.should_receive(:connect).with(mock_slot, :default, subject, :default)
|
36
|
+
subject.from mock_slot
|
37
|
+
end
|
38
|
+
it 'returns the stage itself, for chaining' do
|
39
|
+
subject.from(mock_slot).should == subject
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'set_sink' do
|
44
|
+
it 'returns the actual receiving slot' do
|
45
|
+
# subject.set_sink(:default, mock_stage).should equal(subject)
|
46
|
+
subject.set_sink(mock_stage).should equal(subject)
|
47
|
+
end
|
48
|
+
it 'sets the output attribute' do
|
49
|
+
subject.should_receive(:write_attribute).with(:output, mock_stage)
|
50
|
+
# subject.set_sink(:default, mock_stage)
|
51
|
+
subject.set_sink(mock_stage)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
shared_examples_for 'it can be linked from' do
|
57
|
+
let(:mock_slot){ mock('mock slot') }
|
58
|
+
before do
|
59
|
+
mock_dataflow.stub(:connect).with(subject, :default, mock_slot, :default).and_return([subject, mock_slot])
|
60
|
+
subject.write_attribute(:owner, mock_dataflow)
|
61
|
+
end
|
62
|
+
|
63
|
+
context '#>' do
|
64
|
+
it 'asks its owner to register an edge into self from given stage' do
|
65
|
+
mock_dataflow.should_receive(:connect).with(subject, :default, mock_slot, :default)
|
66
|
+
subject.into mock_slot
|
67
|
+
end
|
68
|
+
it 'returns the output stage' do
|
69
|
+
(subject > mock_slot).should == mock_slot
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context '#into' do
|
74
|
+
it 'asks its owner to register an edge into self from given stage' do
|
75
|
+
mock_dataflow.should_receive(:connect).with(subject, :default, mock_slot, :default)
|
76
|
+
subject.into mock_slot
|
77
|
+
end
|
78
|
+
it 'returns the stage itself, for chaining' do
|
79
|
+
subject.into(mock_slot).should == subject
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'set_input' do
|
84
|
+
it 'returns the actual receiving slot' do
|
85
|
+
subject.set_source(mock_stage).should equal(subject)
|
86
|
+
end
|
87
|
+
it 'sets the input attribute' do
|
88
|
+
subject.should_receive(:write_attribute).with(:input, mock_stage)
|
89
|
+
subject.set_source(mock_stage)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Wukong
|
2
|
+
module Local
|
3
|
+
module IntegrationHelper
|
4
|
+
|
5
|
+
def root
|
6
|
+
@root ||= Pathname.new(File.expand_path('../../..', __FILE__))
|
7
|
+
end
|
8
|
+
|
9
|
+
def lib_dir *args
|
10
|
+
root.join('lib', *args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def bin_dir *args
|
14
|
+
root.join('bin', *args)
|
15
|
+
end
|
16
|
+
|
17
|
+
def examples_dir *args
|
18
|
+
root.join('examples', *args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def integration_env
|
22
|
+
{
|
23
|
+
"PATH" => [bin_dir.to_s, ENV["PATH"]].compact.join(':'),
|
24
|
+
"RUBYLIB" => [lib_dir.to_s, ENV["RUBYLIB"]].compact.join(':')
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def integration_cwd
|
29
|
+
root.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def example_script *args
|
33
|
+
examples_dir(*args)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'gorillib/utils/nuke_constants'
|
2
|
+
require 'gorillib/utils/capture_output'
|
3
|
+
|
4
|
+
module Gorillib ; module Test ; end ; end
|
5
|
+
module Meta ; module Gorillib ; module Test ; end ; end ; end
|
6
|
+
|
7
|
+
shared_context 'model', :model_spec do
|
8
|
+
include Gorillib::TestHelpers
|
9
|
+
|
10
|
+
after(:each){ Gorillib::Test.nuke_constants ; Meta::Gorillib::Test.nuke_constants }
|
11
|
+
|
12
|
+
let(:mock_val){ double('mock value') }
|
13
|
+
|
14
|
+
let(:smurf_class) do
|
15
|
+
class Gorillib::Test::Smurf
|
16
|
+
include Gorillib::Model
|
17
|
+
field :name, String
|
18
|
+
field :smurfiness, Integer
|
19
|
+
field :weapon, Symbol
|
20
|
+
end
|
21
|
+
Gorillib::Test::Smurf
|
22
|
+
end
|
23
|
+
let(:papa_smurf ){ smurf_class.receive(:name => 'Papa Smurf', :smurfiness => 9, :weapon => 'staff') }
|
24
|
+
let(:smurfette ){ smurf_class.receive(:name => 'Smurfette', :smurfiness => 11, :weapon => 'charm') }
|
25
|
+
|
26
|
+
let(:smurf_collection_class) do
|
27
|
+
smurf_class
|
28
|
+
class Gorillib::Test::SmurfCollection < Gorillib::ModelCollection
|
29
|
+
include Gorillib::Collection::ItemsBelongTo
|
30
|
+
self.item_type = Gorillib::Test::Smurf
|
31
|
+
self.parentage_method = :village
|
32
|
+
end
|
33
|
+
Gorillib::Test::SmurfCollection
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:smurf_village_class) do
|
37
|
+
smurf_class ; smurf_collection_class
|
38
|
+
module Gorillib::Test
|
39
|
+
class SmurfVillage
|
40
|
+
include Gorillib::Model
|
41
|
+
field :name, Symbol
|
42
|
+
collection :smurfs, SmurfCollection, item_type: Smurf, key_method: :name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
Gorillib::Test::SmurfVillage
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:smurfhouse_class) do
|
49
|
+
module Gorillib::Test
|
50
|
+
class Smurfhouse
|
51
|
+
include Gorillib::Model
|
52
|
+
field :shape, Symbol
|
53
|
+
field :color, Symbol
|
54
|
+
end
|
55
|
+
end
|
56
|
+
Gorillib::Test::Smurfhouse
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
shared_context 'builder', :model_spec, :builder_spec do
|
62
|
+
let(:engine_class) do
|
63
|
+
class Gorillib::Test::Engine
|
64
|
+
include Gorillib::Builder
|
65
|
+
magic :name, Symbol, :default => ->{ "#{owner? ? owner.name : ''} engine"}
|
66
|
+
magic :carburetor, Symbol, :default => :stock
|
67
|
+
magic :volume, Integer, :doc => 'displacement volume, in in^3'
|
68
|
+
magic :cylinders, Integer
|
69
|
+
member :owner, Whatever
|
70
|
+
self
|
71
|
+
end
|
72
|
+
Gorillib::Test::Engine
|
73
|
+
end
|
74
|
+
|
75
|
+
let(:car_class) do
|
76
|
+
engine_class
|
77
|
+
class Gorillib::Test::Car
|
78
|
+
include Gorillib::Builder
|
79
|
+
magic :name, Symbol
|
80
|
+
magic :make_model, String
|
81
|
+
magic :year, Integer
|
82
|
+
magic :doors, Integer
|
83
|
+
member :engine, Gorillib::Test::Engine
|
84
|
+
self
|
85
|
+
end
|
86
|
+
Gorillib::Test::Car
|
87
|
+
end
|
88
|
+
|
89
|
+
let(:garage_class) do
|
90
|
+
car_class
|
91
|
+
class Gorillib::Test::Garage
|
92
|
+
include Gorillib::Builder
|
93
|
+
collection :cars, Gorillib::Test::Car, key_method: :name
|
94
|
+
self
|
95
|
+
end
|
96
|
+
Gorillib::Test::Garage
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:wildcat) do
|
100
|
+
car_class.receive( :name => :wildcat,
|
101
|
+
:make_model => 'Buick Wildcat', :year => 1968, :doors => 2,
|
102
|
+
:engine => { :volume => 455, :cylinders => 8 } )
|
103
|
+
end
|
104
|
+
let(:ford_39) do
|
105
|
+
car_class.receive( :name => :ford_39,
|
106
|
+
:make_model => 'Ford Tudor Sedan', :year => 1939, :doors => 2, )
|
107
|
+
end
|
108
|
+
let(:garage) do
|
109
|
+
garage_class.new
|
110
|
+
end
|
111
|
+
let(:example_engine) do
|
112
|
+
engine_class.new( :name => 'Geo Metro 1.0L', :volume => 61, :cylinders => 3 )
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
shared_context "graphs" do
|
2
|
+
|
3
|
+
let(:empty_graph) do
|
4
|
+
Hanuman::Graph.receive({})
|
5
|
+
end
|
6
|
+
|
7
|
+
let(:single_stage_graph) do
|
8
|
+
Hanuman::Graph.receive({stages: {first: Hanuman::Stage.receive(label: :first)}})
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:graph) do
|
12
|
+
Hanuman::Graph.receive(stages: {
|
13
|
+
first_a: Hanuman::Stage.receive(label: :first_a), # ancestor
|
14
|
+
first_b: Hanuman::Stage.receive(label: :first_b), # ancestor,
|
15
|
+
second: Hanuman::Stage.receive(label: :second), # ancestor, descendent
|
16
|
+
third_a: Hanuman::Stage.receive(label: :third_a), # ancestor, descendent
|
17
|
+
third_b: Hanuman::Stage.receive(label: :third_b), # descendent
|
18
|
+
fourth: Hanuman::Stage.receive(label: :fourth), # descendent
|
19
|
+
},
|
20
|
+
links: [
|
21
|
+
Hanuman::LinkFactory.connect(:simple, :first_a, :second),
|
22
|
+
Hanuman::LinkFactory.connect(:simple, :first_b, :second),
|
23
|
+
Hanuman::LinkFactory.connect(:simple, :second, :third_a),
|
24
|
+
Hanuman::LinkFactory.connect(:simple, :second, :third_b),
|
25
|
+
Hanuman::LinkFactory.connect(:simple, :third_a, :fourth),
|
26
|
+
]
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:empty_tree) do
|
31
|
+
Hanuman::Tree.receive({})
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:single_stage_tree) do
|
35
|
+
Hanuman::Tree.receive({stages: { first: Hanuman::Stage.receive(label: :first)}})
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:tree) do
|
39
|
+
Hanuman::Tree.receive(stages: {
|
40
|
+
# important to mix up the order here so we
|
41
|
+
# can ensure that tree-sorting is working.
|
42
|
+
first: Hanuman::Stage.receive(label: :first), # ancestor,
|
43
|
+
third_b: Hanuman::Stage.receive(label: :third_b), # descendent
|
44
|
+
second: Hanuman::Stage.receive(label: :second), # ancestor, descendent
|
45
|
+
fourth: Hanuman::Stage.receive(label: :fourth), # descendent
|
46
|
+
third_a: Hanuman::Stage.receive(label: :third_a), # ancestor, descendent
|
47
|
+
},
|
48
|
+
links: [
|
49
|
+
Hanuman::LinkFactory.connect(:simple, :first, :second),
|
50
|
+
Hanuman::LinkFactory.connect(:simple, :second, :third_a),
|
51
|
+
Hanuman::LinkFactory.connect(:simple, :second, :third_b),
|
52
|
+
Hanuman::LinkFactory.connect(:simple, :third_a, :fourth),
|
53
|
+
]
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|