eric-adhearsion 0.7.999 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -2
- data/EVENTS +11 -0
- data/Rakefile +96 -24
- data/adhearsion.gemspec +148 -0
- data/app_generators/ahn/ahn_generator.rb +24 -9
- data/app_generators/ahn/templates/.ahnrc +25 -3
- data/app_generators/ahn/templates/Rakefile +22 -2
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
- data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
- data/app_generators/ahn/templates/config/startup.rb +3 -6
- data/app_generators/ahn/templates/dialplan.rb +2 -3
- data/app_generators/ahn/templates/events.rb +32 -0
- data/bin/jahn +10 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion.rb +17 -11
- data/lib/adhearsion/cli.rb +141 -24
- data/lib/adhearsion/component_manager.rb +169 -238
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
- data/lib/adhearsion/events_support.rb +84 -0
- data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
- data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
- data/lib/adhearsion/foundation/event_socket.rb +203 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
- data/lib/adhearsion/host_definitions.rb +5 -1
- data/lib/adhearsion/initializer.rb +229 -73
- data/lib/adhearsion/initializer/asterisk.rb +33 -11
- data/lib/adhearsion/initializer/configuration.rb +58 -6
- data/lib/adhearsion/initializer/database.rb +3 -46
- data/lib/adhearsion/initializer/drb.rb +9 -3
- data/lib/adhearsion/initializer/freeswitch.rb +3 -3
- data/lib/adhearsion/initializer/rails.rb +1 -1
- data/lib/adhearsion/tasks.rb +2 -1
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/version.rb +3 -3
- data/lib/adhearsion/voip/asterisk.rb +2 -2
- data/lib/adhearsion/voip/asterisk/agi_server.rb +9 -6
- data/lib/adhearsion/voip/asterisk/commands.rb +106 -4
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/call.rb +51 -2
- data/lib/adhearsion/voip/dial_plan.rb +74 -61
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
- data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
- data/lib/theatre.rb +151 -0
- data/lib/theatre/README.markdown +64 -0
- data/lib/theatre/callback_definition_loader.rb +84 -0
- data/lib/theatre/guid.rb +23 -0
- data/lib/theatre/invocation.rb +121 -0
- data/lib/theatre/namespace_manager.rb +153 -0
- data/lib/theatre/version.rb +2 -0
- metadata +63 -138
- data/Manifest.txt +0 -149
- data/README.txt +0 -6
- data/ahn_generators/component/USAGE +0 -5
- data/ahn_generators/component/component_generator.rb +0 -57
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
- data/ahn_generators/component/templates/test/test.rb.erb +0 -12
- data/ahn_generators/component/templates/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/guid.rb +0 -5
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/numeric.rb +0 -4
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
- data/lib/adhearsion/core_extensions/publishable.rb +0 -73
- data/lib/adhearsion/core_extensions/string.rb +0 -26
- data/lib/adhearsion/core_extensions/thread.rb +0 -13
- data/lib/adhearsion/core_extensions/time.rb +0 -0
- data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +0 -57
- data/lib/adhearsion/initializer/paths.rb +0 -55
- data/lib/adhearsion/services/scheduler.rb +0 -5
- data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/spec/fixtures/dialplan.rb +0 -3
- data/spec/initializer/test_configuration.rb +0 -267
- data/spec/initializer/test_loading.rb +0 -162
- data/spec/initializer/test_paths.rb +0 -43
- data/spec/silence.rb +0 -10
- data/spec/test_ahn_command.rb +0 -149
- data/spec/test_code_quality.rb +0 -87
- data/spec/test_component_manager.rb +0 -97
- data/spec/test_constants.rb +0 -8
- data/spec/test_drb.rb +0 -104
- data/spec/test_helper.rb +0 -94
- data/spec/test_hooks.rb +0 -37
- data/spec/test_host_definitions.rb +0 -79
- data/spec/test_initialization.rb +0 -105
- data/spec/test_logging.rb +0 -80
- data/spec/test_relationship_properties.rb +0 -54
- data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
- data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
- data/spec/voip/asterisk/mock_ami_server.rb +0 -176
- data/spec/voip/asterisk/test_agi_server.rb +0 -451
- data/spec/voip/asterisk/test_ami.rb +0 -227
- data/spec/voip/asterisk/test_commands.rb +0 -2006
- data/spec/voip/asterisk/test_config_manager.rb +0 -129
- data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
- data/spec/voip/dsl/test_dispatcher.rb +0 -82
- data/spec/voip/dsl/test_parser.rb +0 -87
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_oes_server.rb +0 -9
- data/spec/voip/test_call_routing.rb +0 -127
- data/spec/voip/test_dialplan_manager.rb +0 -372
- data/spec/voip/test_numerical_string.rb +0 -48
- data/spec/voip/test_phone_number.rb +0 -36
- data/test/test_ahn_generator.rb +0 -59
- data/test/test_component_generator.rb +0 -52
- data/test/test_generator_helper.rb +0 -20
@@ -1,162 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
-
require 'adhearsion/initializer/database'
|
3
|
-
require 'adhearsion/initializer/asterisk'
|
4
|
-
require 'adhearsion/initializer/rails'
|
5
|
-
require 'active_record'
|
6
|
-
|
7
|
-
context "The database initializer" do
|
8
|
-
|
9
|
-
include DatabaseInitializationTestHelper
|
10
|
-
|
11
|
-
test "starts a connection through ActiveRecord" do
|
12
|
-
connection_options = { :adapter => "sqlite3",
|
13
|
-
:dbfile => "foo.sqlite3" }
|
14
|
-
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:require_models).once
|
15
|
-
flexmock(ActiveRecord::Base).should_receive(:establish_connection).with(connection_options)
|
16
|
-
|
17
|
-
start_database_initializer_with_options connection_options
|
18
|
-
end
|
19
|
-
|
20
|
-
test "should make any required models available in the main namespace" do
|
21
|
-
bogus_model = tempfile_with_contents sample_user_model
|
22
|
-
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:all_models).and_return([bogus_model.path])
|
23
|
-
start_database_initializer
|
24
|
-
User.superclass.should.equal ActiveRecord::Base
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'should enable ActiveRecord concurrency' do
|
28
|
-
bogus_model = tempfile_with_contents sample_user_model
|
29
|
-
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:all_models).and_return([bogus_model.path])
|
30
|
-
start_database_initializer
|
31
|
-
ActiveRecord::Base.send(:class_variable_get, :@@allow_concurrency).should.be true
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
context "The Asterisk initializer" do
|
37
|
-
|
38
|
-
include AsteriskInitializerTestHelper
|
39
|
-
|
40
|
-
test "starts the AGI server" do
|
41
|
-
initialize_asterisk_with_defaults
|
42
|
-
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once
|
43
|
-
end
|
44
|
-
|
45
|
-
test "starts the AGI server with any overridden settings" do
|
46
|
-
overrides = {:host => "127.0.0.1", :port => 7788}
|
47
|
-
config_overrides = {:listening_host => overrides[:host], :listening_port => overrides[:port]}
|
48
|
-
initialize_asterisk_with_options config_overrides
|
49
|
-
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once.with(overrides)
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
context "The Rails initializer" do
|
55
|
-
|
56
|
-
include RailsInitializerTestHelper
|
57
|
-
|
58
|
-
test "should load the config/environment.rb file within the rails_root path" do
|
59
|
-
rails_root = "/path/to/rails/app"
|
60
|
-
environment_rb = rails_root + '/config/environment.rb'
|
61
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.with environment_rb
|
62
|
-
stub_file_checking_methods!
|
63
|
-
stub_before_call_hook!
|
64
|
-
initialize_rails_with_options :rails_root => rails_root, :environment => :development
|
65
|
-
end
|
66
|
-
|
67
|
-
test "should raise an exception if the database is initialized at the same time" do
|
68
|
-
flexmock(Adhearsion::AHN_CONFIG).should_receive(:database_enabled?).and_return true
|
69
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).and_return
|
70
|
-
stub_file_checking_methods!
|
71
|
-
stub_before_call_hook!
|
72
|
-
the_following_code {
|
73
|
-
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
74
|
-
}.should.raise
|
75
|
-
end
|
76
|
-
|
77
|
-
test "should set the RAILS_ENV to be the argument passed in" do
|
78
|
-
flexmock(ENV).should_receive(:[]=).once.with("RAILS_ENV", "development")
|
79
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.and_return
|
80
|
-
stub_file_checking_methods!
|
81
|
-
stub_before_call_hook!
|
82
|
-
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'should enable ActiveRecord concurrency' do
|
86
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :require
|
87
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :load_rails
|
88
|
-
stub_file_checking_methods!
|
89
|
-
stub_before_call_hook!
|
90
|
-
initialize_rails_with_options :rails_root => '/path/somewhere', :environment => :development
|
91
|
-
ActiveRecord::Base.send(:class_variable_get, :@@allow_concurrency).should.equal true
|
92
|
-
end
|
93
|
-
|
94
|
-
test 'should create a BeforeCall hook (presumably to verify the active connections)' do
|
95
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :require
|
96
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :load_rails
|
97
|
-
stub_file_checking_methods!
|
98
|
-
flexmock(Adhearsion::Hooks::BeforeCall).should_receive(:create_hook).once
|
99
|
-
initialize_rails_with_options :rails_root => '/path/somewhere', :environment => :development
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
BEGIN {
|
105
|
-
module DatabaseInitializationTestHelper
|
106
|
-
|
107
|
-
def start_database_initializer
|
108
|
-
start_database_initializer_with_options :adapter => "sqlite3", :dbfile => "foobar.sqlite3"
|
109
|
-
end
|
110
|
-
|
111
|
-
def start_database_initializer_with_options(options)
|
112
|
-
Adhearsion::Configuration.configure { |config| config.enable_database(options) }
|
113
|
-
Adhearsion::Initializer::DatabaseInitializer.start
|
114
|
-
end
|
115
|
-
|
116
|
-
def tempfile_with_contents(contents)
|
117
|
-
returning Tempfile.new("bogus_model") do |file|
|
118
|
-
file.puts contents
|
119
|
-
file.flush
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def sample_user_model
|
124
|
-
<<-CODE
|
125
|
-
class User < ActiveRecord::Base
|
126
|
-
validates_uniqueness_of :name
|
127
|
-
end
|
128
|
-
CODE
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
module AsteriskInitializerTestHelper
|
133
|
-
def initialize_asterisk_with_defaults
|
134
|
-
initialize_asterisk_with_options Hash.new
|
135
|
-
end
|
136
|
-
def initialize_asterisk_with_options(options)
|
137
|
-
flexmock(Adhearsion::Initializer::AsteriskInitializer).should_receive(:join_server_thread_after_initialized)
|
138
|
-
Adhearsion::Configuration.configure { |config| config.enable_asterisk(options) }
|
139
|
-
Adhearsion::Initializer::AsteriskInitializer.start
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
module RailsInitializerTestHelper
|
144
|
-
|
145
|
-
def initialize_rails_with_options(options)
|
146
|
-
rails_options = flexmock "Rails options mock", options
|
147
|
-
flexstub(Adhearsion::AHN_CONFIG).should_receive(:rails).once.and_return(rails_options)
|
148
|
-
Adhearsion::Initializer::RailsInitializer.start
|
149
|
-
end
|
150
|
-
|
151
|
-
def stub_file_checking_methods!
|
152
|
-
flexstub(File).should_receive(:directory?).and_return true
|
153
|
-
flexstub(File).should_receive(:exists?).and_return true
|
154
|
-
end
|
155
|
-
|
156
|
-
def stub_before_call_hook!
|
157
|
-
flexstub(Adhearsion::Hooks::BeforeCall).should_receive :create_hook
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
-
|
3
|
-
describe "Adhearsion::Paths" do
|
4
|
-
|
5
|
-
#TODO: All this crap will go away
|
6
|
-
disabled_test "should find all files when given a glob" do
|
7
|
-
inside_initialized_app do |path|
|
8
|
-
tmps = %w"foo.rb BA\ R.gem _q_a_z_.c"
|
9
|
-
tmps.each { |f| FileUtils.touch "#{path}/helpers/#{f}" }
|
10
|
-
found_helpers = all_helpers
|
11
|
-
all_helpers.should.not.be.empty
|
12
|
-
all_helpers.map! {|f| File.basename f }
|
13
|
-
all_helpers.each { |f| all_helpers.should.include(f) }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
test "should find files when several globs are given"
|
17
|
-
|
18
|
-
test "should allow the removal of path managers" do
|
19
|
-
Adhearsion::Paths.manager_for :helpers, :directory => "helpers"
|
20
|
-
Adhearsion::Paths.remove_manager_for :helpers
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "The .ahnrc " do
|
25
|
-
test "should allow ERb"
|
26
|
-
test "should create methods for every path declared"
|
27
|
-
test "should add all_x and x_path methods to main namespace and pluralize names" do
|
28
|
-
Adhearsion::Paths.manager_for "helper", :directory => "helpers"
|
29
|
-
should.respond_to(:all_helpers)
|
30
|
-
should.respond_to(:helper_path)
|
31
|
-
end
|
32
|
-
test "should have an init key"
|
33
|
-
test "should allow a String to the init key"
|
34
|
-
test "should default the init key to config/startup.rb"
|
35
|
-
test "should allow an Array to the init key"
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "Adhearsion's paths syntax sugar" do
|
39
|
-
test "should calculate helper paths properly"
|
40
|
-
test "should find log files properly"
|
41
|
-
test "should find helper config paths properly"
|
42
|
-
test "should return the configuration for a helper properly"
|
43
|
-
end
|
data/spec/silence.rb
DELETED
data/spec/test_ahn_command.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/test_helper"
|
2
|
-
require 'adhearsion/cli'
|
3
|
-
|
4
|
-
module AhnCommandSpecHelper
|
5
|
-
def simulate_args(*args)
|
6
|
-
ARGV.clear
|
7
|
-
ARGV.concat args
|
8
|
-
end
|
9
|
-
|
10
|
-
def capture_stdout(&block)
|
11
|
-
old = $stdout
|
12
|
-
$stdout = io = StringIO.new
|
13
|
-
yield
|
14
|
-
ensure
|
15
|
-
$stdout = old
|
16
|
-
return io.string
|
17
|
-
end
|
18
|
-
|
19
|
-
def new_tmp_dir(filename=String.random)
|
20
|
-
File.join Dir.tmpdir, filename
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'The Ahn Command helper' do
|
27
|
-
|
28
|
-
include AhnCommandSpecHelper
|
29
|
-
|
30
|
-
test "args are simulated properly" do
|
31
|
-
before = ARGV.clone
|
32
|
-
simulate_args "create", "/tmp/blah"
|
33
|
-
ARGV.should.not.equal before
|
34
|
-
end
|
35
|
-
|
36
|
-
test "STDOUT should be captured" do
|
37
|
-
capture_stdout do
|
38
|
-
puts "wee"
|
39
|
-
end.should.equal "wee\n"
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
context "A simulated use of the 'ahn' command" do
|
45
|
-
|
46
|
-
include AhnCommandSpecHelper
|
47
|
-
|
48
|
-
test "USAGE is defined" do
|
49
|
-
assert Adhearsion::CLI::AhnCommand.const_defined?('USAGE')
|
50
|
-
end
|
51
|
-
|
52
|
-
test "arguments to 'create' are executed properly properly" do
|
53
|
-
some_path = "/path/somewhere"
|
54
|
-
simulate_args "create", some_path
|
55
|
-
flexmock(Adhearsion::CLI::AhnCommand::CommandHandler).should_receive(:create).once.with(some_path, :default)
|
56
|
-
capture_stdout { Adhearsion::CLI::AhnCommand.execute! }
|
57
|
-
end
|
58
|
-
|
59
|
-
test "arguments to 'start' are executed properly properly" do
|
60
|
-
some_path = "/tmp/blargh"
|
61
|
-
simulate_args "start", some_path
|
62
|
-
flexmock(Adhearsion::CLI::AhnCommand::CommandHandler).should_receive(:start).once.with(some_path, false, nil)
|
63
|
-
Adhearsion::CLI::AhnCommand.execute!
|
64
|
-
end
|
65
|
-
|
66
|
-
test "should execute arguments to 'start' for daemonizing properly" do
|
67
|
-
somewhere = "/tmp/blarghh"
|
68
|
-
simulate_args "start", 'daemon', somewhere
|
69
|
-
flexmock(Adhearsion::CLI::AhnCommand::CommandHandler).should_receive(:start).once.with(somewhere, true, nil)
|
70
|
-
Adhearsion::CLI::AhnCommand.execute!
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'parse_arguments should recognize start with daemon properly' do
|
74
|
-
path = '/path/to/somesuch'
|
75
|
-
arguments = ["start", 'daemon', path]
|
76
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(arguments).should == [:start, path, true, nil]
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'should recognize start with daemon and pid file properly' do
|
80
|
-
project_path = '/second/star/on/the/right'
|
81
|
-
pid_file_path = '/straight/on/til/morning'
|
82
|
-
arguments = ["start", "daemon", project_path, "--pid-file=#{pid_file_path}"]
|
83
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(arguments).should == [:start, project_path, true, pid_file_path]
|
84
|
-
end
|
85
|
-
|
86
|
-
test 'parse_arguments should recognize start without daemon properly' do
|
87
|
-
path = '/path/to/somewhere'
|
88
|
-
arguments = ['start', path]
|
89
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(arguments).should == [:start, path, false, nil]
|
90
|
-
end
|
91
|
-
|
92
|
-
test "if no path is provided, running Ahn command blows up" do
|
93
|
-
the_following_code {
|
94
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(['start'])
|
95
|
-
}.should.raise Adhearsion::CLI::AhnCommand::CommandHandler::UnknownCommand
|
96
|
-
end
|
97
|
-
|
98
|
-
test "printing the version" do
|
99
|
-
capture_stdout do
|
100
|
-
simulate_args 'version'
|
101
|
-
Adhearsion::CLI::AhnCommand.execute!
|
102
|
-
end.should =~ Regexp.new(Regexp.escape(Adhearsion::VERSION::STRING))
|
103
|
-
end
|
104
|
-
|
105
|
-
test "printing the help" do
|
106
|
-
capture_stdout do
|
107
|
-
simulate_args 'help'
|
108
|
-
Adhearsion::CLI::AhnCommand.execute!
|
109
|
-
end.should =~ Regexp.new(Regexp.escape(Adhearsion::CLI::AhnCommand::USAGE))
|
110
|
-
end
|
111
|
-
|
112
|
-
test "reacting to unrecognized commands" do
|
113
|
-
the_following_code {
|
114
|
-
simulate_args "alpha", "beta"
|
115
|
-
Adhearsion::CLI::AhnCommand.execute!
|
116
|
-
}.should.raise(Adhearsion::CLI::AhnCommand::CommandHandler::UnknownCommand)
|
117
|
-
end
|
118
|
-
|
119
|
-
test "giving a path that doesn't contain a project raises an exception" do
|
120
|
-
the_following_code {
|
121
|
-
simulate_args "start", "/asjdfas/sndjfabsdfbqwb/qnjwejqbwh"
|
122
|
-
Adhearsion::CLI::AhnCommand.execute!
|
123
|
-
}.should.raise(Adhearsion::CLI::AhnCommand::CommandHandler::PathInvalid)
|
124
|
-
end
|
125
|
-
|
126
|
-
test "giving an unrecognized project name raises an exception" do
|
127
|
-
the_following_code {
|
128
|
-
nonexistent_app_name, nonexistent_path = "a2n8y3gny2", "/tmp/qjweqbwas"
|
129
|
-
simulate_args "create:#{nonexistent_app_name}", nonexistent_path
|
130
|
-
Adhearsion::CLI::AhnCommand.execute!
|
131
|
-
}.should.raise Adhearsion::CLI::AhnCommand::CommandHandler::UnknownProject
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'A real use of the "ahn" command' do
|
136
|
-
|
137
|
-
include AhnCommandSpecHelper
|
138
|
-
|
139
|
-
test "the 'create' command" do
|
140
|
-
the_following_code {
|
141
|
-
tmp_path = new_tmp_dir
|
142
|
-
simulate_args "create", tmp_path
|
143
|
-
RubiGen::Base.default_options.merge! :quiet => true
|
144
|
-
capture_stdout { Adhearsion::CLI::AhnCommand.execute! }
|
145
|
-
File.exists?(File.join(tmp_path, ".ahnrc")).should.be true
|
146
|
-
}.should.not.raise
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|
data/spec/test_code_quality.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
# #!/usr/bin/env spec
|
2
|
-
#
|
3
|
-
# # TODO: Forget regexps. Use Rubinius.
|
4
|
-
# # This spec is somewhat unique. It essentially reads the code
|
5
|
-
# # and ensures the best practices are followed.
|
6
|
-
#
|
7
|
-
# # TODO: Create a be_a_proper_method_definition assertion
|
8
|
-
# # TODO: Create a syntax checking spec
|
9
|
-
# # TODO: Report code that has spaces between the dot when defining the method on an object
|
10
|
-
#
|
11
|
-
# module CodeQualityHelper
|
12
|
-
# # TODO: Allow strings with a Hash in them before it
|
13
|
-
#
|
14
|
-
# BadMethodRegexp = /def\s+([$@]?[a-zA-Z_][\w_]*\s*\.\s*)?[a-zA-Z_][\w_]*[=!?]?[^(^\Z]/
|
15
|
-
# @root = File.dirname(__FILE__) + "/.."
|
16
|
-
#
|
17
|
-
# def ruby_files
|
18
|
-
# @ruby_files ||= Dir[@root + "/**/*.rb"].map { |f| File.expand_path f }
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# describe "My 'bad method definition' finding regular expression" do
|
24
|
-
#
|
25
|
-
# # ATTENTION: If this spec ever blows up for a method definition it shouldn't,
|
26
|
-
# # please add the definition that caused it to explode here as an assertion.
|
27
|
-
# # It would also be nice to fix the regular expression too :)
|
28
|
-
#
|
29
|
-
# include CodeQualityHelper
|
30
|
-
#
|
31
|
-
# it "should NOT match method definitions with no arguments" do
|
32
|
-
# "def foo".should !~ CodeQualityHelper::BadMethodRegexp
|
33
|
-
# " def monkey ".should !~ CodeQualityHelper::BadMethodRegexp
|
34
|
-
# ' unless "#{bar}".empty? then def @zebra.spock '.should !~ CodeQualityHelper::BadMethodRegexp
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# it "should NOT match method definitions with arguments and parenthesis" do
|
38
|
-
# "def foo(bar)".should !~ CodeQualityHelper::BadMethodRegexp
|
39
|
-
# "\tdef $MONKEY . foo( bar, qaz = blam!) ".should !~ CodeQualityHelper::BadMethodRegexp
|
40
|
-
# "if(this) then def $MONKEY . foo( qaz = blam!, *args, &b) ".should !~ CodeQualityHelper::BadMethodRegexp
|
41
|
-
# " @something.each do |x| def something".should !~ CodeQualityHelper::BadMethodRegexp
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# it "should match method definitions with a space between the name and parenthesis" do
|
45
|
-
# "def foo (bar)".should =~ CodeQualityHelper::BadMethodRegexp
|
46
|
-
# "def \t m \t (*args)".should =~ CodeQualityHelper::BadMethodRegexp
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# it "should match method definitions with no parenthesis around its arguments" do
|
50
|
-
# "def foo bar".should =~ CodeQualityHelper::BadMethodRegexp
|
51
|
-
# "\tif $x then def foo bar # Commentacular".should =~ CodeQualityHelper::BadMethodRegexp
|
52
|
-
# end
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# describe "All method definitions" do
|
56
|
-
#
|
57
|
-
# include CodeQualityHelper
|
58
|
-
#
|
59
|
-
# before:all do
|
60
|
-
# @root = File.dirname(__FILE__) + "/.."
|
61
|
-
# end
|
62
|
-
#
|
63
|
-
# it "should have parenthesis around their arguments" do
|
64
|
-
# ruby_files.each do |file|
|
65
|
-
# puts file
|
66
|
-
# File.read(file).grep(CodeQualityHelper::BadMethodRegexp).should be_empty
|
67
|
-
# end
|
68
|
-
# end
|
69
|
-
# end
|
70
|
-
#
|
71
|
-
# # describe "The syntax of all Ruby source files" do
|
72
|
-
# #
|
73
|
-
# # include CodeQualityHelper
|
74
|
-
# #
|
75
|
-
# # before:all do
|
76
|
-
# # @root = File.dirname(__FILE__) + "/.."
|
77
|
-
# # end
|
78
|
-
# #
|
79
|
-
# # it "should be valid" do
|
80
|
-
# # incorrect = ruby_files.map { |f| File.expand_path f }.select do |file|
|
81
|
-
# # `ruby -c #{file}`
|
82
|
-
# # not $?.success?
|
83
|
-
# # end
|
84
|
-
# #
|
85
|
-
# # incorrect.should be_empty
|
86
|
-
# # end
|
87
|
-
# # end
|