Permalink
Browse files

faker specs were targeting factory classes not instances.

  • Loading branch information...
Philip (flip) Kromer
Philip (flip) Kromer committed Jun 18, 2012
1 parent e1a9f25 commit e42ac260f8dab6b4adaa042b0f6cbfe3526eae40
@@ -1,6 +1,5 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path("../lib", File.realdirpath(File.dirname(__FILE__))))
-
require 'wukong'
Settings.use(:commandline)
@@ -15,15 +14,34 @@
Parses an apache log line into a structured model, emits it as JSON
DOC
- input :default, stdin # file_source(Pathname.path_to(:data, 'log/sample_apache_log.log'))
+ source = ($0 == __FILE__) ? stdin : file_source(Pathname.path_to(:data, 'log/sample_apache_log.log'))
+ input :default, source
output :dump, stdout
input(:default) >
map{|line| ApacheLogLine.make(line) or bad_record(line) } >
- # to_json >
to_tsv >
output(:dump)
-
end
-Wukong::LocalRunner.run(Wukong.dataflow(:parse_apache_logs), :default)
+if ($0 == __FILE__)
+ flow_name = :parse_apache_logs
+ if Settings.profiler
+ require 'perftools'
+ Pathname(Settings.profiler).dirname.mkpath
+ PerfTools::CpuProfiler.start(Settings.profiler) do
+ Wukong::LocalRunner.run(Wukong.dataflow(flow_name), :default)
+ end
+ else
+ Wukong::LocalRunner.run(Wukong.dataflow(flow_name), :default)
+ end
+
+ # require 'jruby/profiler'
+ # profile_data = JRuby::Profiler.profile do
+ # Wukong::LocalRunner.run(Wukong.dataflow(flow_name), :default)
+ # end
+ # profile_printer = JRuby::Profiler::GraphProfilePrinter.new(profile_data)
+ # profile_printer.printProfile($stderr)
+
+ # Wukong::LocalRunner.run(Wukong.dataflow(flow_name), :default)
+end
View
@@ -110,27 +110,27 @@ def fake_value(opts={})
end
end
- def StringFactory.fake_value() ; receive(Wukong::Faker::Helpers.fake_word) ; end
- def GuidFactory.fake_value() ; receive(UUIDTools::UUID.random_create.to_s) ; end
- def HostnameFactory.fake_value() ; receive(Wukong::Faker::Helpers.fake_hostname) ; end
- def IpAddressFactory.fake_value() ; receive(Wukong::Faker::Helpers.fake_ip_addresss) ; end
+ StringFactory.class_eval{ def fake_value() ; receive(Wukong::Faker::Helpers.fake_word) ; end }
+ GuidFactory.class_eval{ def fake_value() ; receive(UUIDTools::UUID.random_create.to_s) ; end }
+ HostnameFactory.class_eval{ def fake_value() ; receive(Wukong::Faker::Helpers.fake_hostname) ; end }
+ IpAddressFactory.class_eval{ def fake_value() ; receive(Wukong::Faker::Helpers.fake_ip_addresss) ; end }
- def SymbolFactory.fake_value() ; receive(Wukong::Faker::Helpers.fake_identifier) end
- def PathnameFactory.fake_value() ; receive(Wukong::Faker::Helpers.fake_filename) end
+ SymbolFactory.class_eval{ def fake_value() ; receive(Wukong::Faker::Helpers.fake_identifier) end }
+ PathnameFactory.class_eval{ def fake_value() ; receive(Wukong::Faker::Helpers.fake_filename) end }
- def IntegerFactory.fake_value(opts={}) ; receive(Wukong::Faker::Helpers.fake_integer(opts)) ; end
- def BignumFactory.fake_value(opts={}) ; super({:min => 2**68, :max => 2**90}.merge(opts)) ; end
+ IntegerFactory.class_eval{ def fake_value(opts={}) ; receive(Wukong::Faker::Helpers.fake_integer(opts)) ; end }
+ BignumFactory.class_eval{ def fake_value(opts={}) ; super({:min => 2**68, :max => 2**90}.merge(opts)) ; end }
- def FloatFactory.fake_value(opts={}) ; receive(Wukong::Faker::Helpers.fake_float(opts)) ; end
- def ComplexFactory.fake_value() ; receive(Kernel.rand, Kernel.rand) ; end
- def RationalFactory.fake_value() ; receive(Kernel.rand.to_r) ; end
+ FloatFactory.class_eval{ def fake_value(opts={}) ; receive(Wukong::Faker::Helpers.fake_float(opts)) ; end }
+ ComplexFactory.class_eval{ def fake_value() ; receive(Kernel.rand, Kernel.rand) ; end }
+ RationalFactory.class_eval{ def fake_value() ; receive(Kernel.rand.to_r) ; end }
- def TimeFactory.fake_value() ; receive(Time.now) ; end
+ TimeFactory.class_eval{ def fake_value() ; receive(Time.now) ; end }
- def ExceptionFactory.fake_value() ; Exception.constants.sample ; end
-
- def NilFactory.fake_value() ; nil ; end
- def TrueFactory.fake_value() ; true ; end
- def FalseFactory.fake_value() ; false ; end
- def BooleanFactory.fake_value() ; [true, false].sample ; end
+ ExceptionFactory.class_eval{ def fake_value() ; Exception.constants.sample ; end }
+
+ NilFactory.class_eval{ def fake_value() ; nil ; end }
+ TrueFactory.class_eval{ def fake_value() ; true ; end }
+ FalseFactory.class_eval{ def fake_value() ; false ; end }
+ BooleanFactory.class_eval{ def fake_value() ; [true, false].sample ; end }
end
@@ -3,11 +3,12 @@
describe_example_script(:parse_apache_logs, 'dataflow/parse_apache_logs.rb') do
it 'runs' do
+ subject = Wukong.dataflow(:parse_apache_logs)
out, err = Gorillib::TestHelpers.capture_output do
Wukong::LocalRunner.receive(:flow => subject) do
run :default
end
end
- out.string.split("\n").first.should =~ /\{\"ip_address\":\"[\d\.]+\",.*\"}/
+ out.string.split("\n").first.should == "127.0.0.1 - - [10/Apr/2007:10:39:11 +0300] \"GET / HTTP/1.1\" 500 606 \"-\" \"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20061201 Firefox/2.0.0.3 (Ubuntu-feisty)\"\t"
end
end
@@ -17,6 +17,9 @@ def self.the(class_method, &block)
let(:mock_stage ){ m = mock('mock stage') ; m }
let(:mock_processor){ m = mock ; m.stub(:name => 'mock processor', :attributes => { :a => :b }) ; m }
+ let(:test_model_class){ Class.new{ include Gorillib::Model ; field :smurfiness, Integer } }
+ let(:test_model){ test_model_class.receive(:smurfiness => 99) }
+
let(:test_source){ Wukong::Integers.new(:name => :integers, :size => 100) }
let(:test_sink){ Wukong::Sink::ArraySink.new(:name => :test_sink) }
let(:test_processor_class){ Wukong::AsIs }
@@ -9,7 +9,7 @@
it 'using type if no faker given' do
subject.field :last_name, String
- Gorillib::Factory::StringFactory.should_receive(:fake_value)
+ Gorillib::Factory(String).should_receive(:fake_value)
subject.fake_value
end
@@ -27,8 +27,8 @@
end
it 'with explicit faker factory' do
- subject.field :longitude, String, :faker => Gorillib::Factory::IntegerFactory
- Gorillib::Factory::IntegerFactory.should_receive(:fake_value)
+ subject.field :longitude, String, :faker => Gorillib::Factory(Integer)
+ Gorillib::Factory(Integer).should_receive(:fake_value)
subject.fake_value
end
@@ -54,41 +54,40 @@
be_ish_matcher :ip_address, /^(\d+\.){3}\d+$/
context 'extensions to Gorillib::Factory' do
- context Gorillib::Factory::StringFactory do
- the(:fake_value){ should =~ /^\w+$/ }
+ context Gorillib::Factory(String) do
+ its(:fake_value){ should =~ /^\w+$/ }
end
- context(Gorillib::Factory::GuidFactory) do
- the(:fake_value){ should be_guid_ish }
+ context(Gorillib::Factory(Guid)) do
+ its(:fake_value){ should be_guid_ish }
end
- context(Gorillib::Factory::IpAddressFactory) do
- the(:fake_value){ should be_ip_address_ish }
+ context(Gorillib::Factory(IpAddress)) do
+ its(:fake_value){ should be_ip_address_ish }
end
- context(Gorillib::Factory::HostnameFactory) do
- the(:fake_value){ should be_hostname_ish }
+ context(Gorillib::Factory(Hostname)) do
+ its(:fake_value){ should be_hostname_ish }
end
- context(Gorillib::Factory::SymbolFactory) do
- the(:fake_value){ should be_a Symbol }
- the(:fake_value){ should be_identifier_ish }
+ context(Gorillib::Factory(Symbol)) do
+ its(:fake_value){ should be_a Symbol }
+ its(:fake_value){ should be_identifier_ish }
end
- context(Gorillib::Factory::IntegerFactory) do
- the(:fake_value){ should be_a Integer }
- the(:fake_value){ should be < 100 }
+ context(Gorillib::Factory(Integer)) do
+ its(:fake_value){ should be_a Integer }
+ its(:fake_value){ should be < 100 }
end
- context(Gorillib::Factory::TimeFactory) do
- the(:fake_value){ should be_a Time }
- the(:fake_value){ should be_within(5).of(Time.now) }
+ context(Gorillib::Factory(Time)) do
+ its(:fake_value){ should be_a Time }
+ its(:fake_value){ should be_within(5).of(Time.now) }
end
- context(Gorillib::Factory::NilFactory ){ the(:fake_value){ should equal(nil) } }
- context(Gorillib::Factory::TrueFactory ){ the(:fake_value){ should equal(true) } }
- context(Gorillib::Factory::FalseFactory ){ the(:fake_value){ should equal(false) } }
- context(Gorillib::Factory::BooleanFactory){ the(:fake_value){ should be_in([true, false]) } }
+ context(Gorillib::Factory(NilClass) ){ its(:fake_value){ should equal(nil) } }
+ context(Gorillib::Factory(TrueClass) ){ its(:fake_value){ should equal(true) } }
+ context(Gorillib::Factory(FalseClass) ){ its(:fake_value){ should equal(false) } }
+ context(Gorillib::Factory(:boolean) ){ its(:fake_value){ should be_in([true, false]) } }
end
-
context Wukong::Faker::Helpers do
subject{ Wukong::Faker::Helpers }
@@ -129,6 +128,6 @@
its(:fake_ip_addresss){ should be_ip_address_ish }
its(:fake_version_number){ should be_a(String) }
its(:fake_version_number){ should =~ /^\d+\.\d+$/ }
-
end
+
end

0 comments on commit e42ac26

Please sign in to comment.