ti 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +43 -0
  2. data/Gemfile +2 -19
  3. data/Gemfile.lock +27 -27
  4. data/LICENSE.txt +1 -1
  5. data/README.rdoc +1 -1
  6. data/Rakefile +0 -28
  7. data/TODO.mkd +1 -2
  8. data/lib/ti.rb +10 -10
  9. data/lib/ti/cli.rb +39 -6
  10. data/lib/ti/config.rb +22 -0
  11. data/lib/ti/generate/controller.rb +38 -0
  12. data/lib/ti/generate/model.rb +13 -7
  13. data/lib/ti/generate/project.rb +59 -13
  14. data/lib/ti/generate/view.rb +30 -9
  15. data/lib/ti/templates/app/controllers/controller.erb +0 -0
  16. data/lib/ti/templates/app/controllers/window.erb +3 -0
  17. data/lib/ti/templates/app/views/tabgroup.erb +0 -0
  18. data/lib/ti/templates/app/views/view.erb +0 -0
  19. data/lib/ti/templates/app/views/window.erb +3 -0
  20. data/lib/ti/templates/{guardfile → defaults/Guardfile.erb} +3 -3
  21. data/lib/ti/templates/defaults/Rakefile.erb +148 -0
  22. data/lib/ti/templates/defaults/Readme.mkd.erb +1 -0
  23. data/lib/ti/templates/{config → defaults/config.erb} +1 -1
  24. data/lib/ti/templates/gitignore +1 -1
  25. data/lib/ti/templates/specs/app_spec.coffee +2 -2
  26. data/lib/ti/utils.rb +70 -41
  27. data/lib/ti/version.rb +3 -0
  28. data/spec/cli/command_spec.rb +7 -11
  29. data/spec/fixtures/configs/tiapp.xml +34 -0
  30. data/spec/lib/config_spec.rb +34 -0
  31. data/spec/spec_helper.rb +8 -0
  32. data/spec/ti/generators/model_spec.rb +25 -0
  33. data/spec/ti/generators/project_spec.rb +121 -0
  34. data/spec/ti/generators/view_spec.rb +25 -0
  35. data/spec/ti/logger_spec.rb +25 -0
  36. data/spec/ti/utils_spec.rb +120 -0
  37. data/ti.gemspec +32 -103
  38. metadata +75 -47
  39. data/VERSION +0 -1
  40. data/lib/ti/options.rb +0 -64
  41. data/lib/ti/parse_options.rb +0 -48
  42. data/lib/ti/templates/readme +0 -1
@@ -0,0 +1,3 @@
1
+ module Ti
2
+ VERSION = "0.1.0"
3
+ end
@@ -47,20 +47,16 @@ describe "Ti Generator Commands" do
47
47
  end
48
48
  end
49
49
  context "Generate a new project: " do
50
- context "with defaults (ti new)" do
51
- it "should generate new project \"HelloWorld\"" do
52
- response, status = capture_with_status(:stdout){ Ti::CLI.start(['new']) }
53
- response.should eql("")
54
- status.should eql(Ti::CLI::STATUS_TYPES[:success])
55
- end
56
- after (:all) do
57
- remove_directories("HelloWorld")
50
+ context "with no name (ti new)" do
51
+ it "should exit with error" do
52
+ response, status = capture_with_status(:stderr){ Ti::CLI.start(['new']) }
53
+ response.should eql("\"new\" was called incorrectly. Call as \"rspec new <name> <id> <platform>\".\n")
58
54
  end
59
55
  end
60
56
  context "with custom name (ti new Demo)" do
61
57
  it "should generate new project \"Demo\"" do
62
58
  response, status = capture_with_status(:stdout){ Ti::CLI.start(['new', 'Demo']) }
63
- response.should eql("\e[1m\e[32mCreating the tmp directory.\e[0m\e[0m\n\e[1m\e[32mRemoving README file.\e[0m\e[0m\n\e[1m\e[32mRemoving Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/images directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/vendor directory.\e[0m\e[0m\n\e[1m\e[32mCreating the config directory.\e[0m\e[0m\n\e[1m\e[32mCreating the docs directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/stylesheets directory.\e[0m\e[0m\n\e[1m\e[32mCreating the specs/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the specs/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd file.\e[0m\e[0m\n\e[1m\e[32mCreating app/app.coffee\e[0m\e[0m\n\e[1m\e[32mCreating .gitignore\e[0m\e[0m\n\e[1m\e[32mCreating config/config.rb\e[0m\e[0m\n\e[1m\e[32mCreating Rakefile\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd\e[0m\e[0m\n\e[1m\e[32mCreating Guardfile\e[0m\e[0m\n\e[1m\e[32mCreating specs/app_spec.coffee\e[0m\e[0m\n\e[1m\e[32mYour Titanium project is ready for you to get rockin!\e[0m\e[0m\n")
59
+ response.should eql("\e[1m\e[32mCreating the tmp directory.\e[0m\e[0m\n\e[1m\e[32mRemoving README file.\e[0m\e[0m\n\e[1m\e[32mRemoving Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/images directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/vendor directory.\e[0m\e[0m\n\e[1m\e[32mCreating the config directory.\e[0m\e[0m\n\e[1m\e[32mCreating the docs directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/stylesheets directory.\e[0m\e[0m\n\e[1m\e[32mCreating the spec/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the spec/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd file.\e[0m\e[0m\n\e[1m\e[32mCreating app/app.coffee\e[0m\e[0m\n\e[1m\e[32mCreating .gitignore\e[0m\e[0m\n\e[1m\e[32mCreating spec/app_spec.coffee\e[0m\e[0m\n\e[1m\e[32mYour Titanium project is ready for you to get rockin!\e[0m\e[0m\n")
64
60
  status.should eql(Ti::CLI::STATUS_TYPES[:success])
65
61
  end
66
62
  after (:all) do
@@ -70,7 +66,7 @@ describe "Ti Generator Commands" do
70
66
  context "with custom name and id (ti new Demo com.mycompany.demo)" do
71
67
  it "should generate new project \"Demo\" with id \"com.mycompany.demo\"" do
72
68
  response, status = capture_with_status(:stdout){ Ti::CLI.start(['new', 'Demo', 'com.mycompany.demo']) }
73
- response.should eql("\e[1m\e[32mCreating the tmp directory.\e[0m\e[0m\n\e[1m\e[32mRemoving README file.\e[0m\e[0m\n\e[1m\e[32mRemoving Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/images directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/vendor directory.\e[0m\e[0m\n\e[1m\e[32mCreating the config directory.\e[0m\e[0m\n\e[1m\e[32mCreating the docs directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/stylesheets directory.\e[0m\e[0m\n\e[1m\e[32mCreating the specs/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the specs/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd file.\e[0m\e[0m\n\e[1m\e[32mCreating app/app.coffee\e[0m\e[0m\n\e[1m\e[32mCreating .gitignore\e[0m\e[0m\n\e[1m\e[32mCreating config/config.rb\e[0m\e[0m\n\e[1m\e[32mCreating Rakefile\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd\e[0m\e[0m\n\e[1m\e[32mCreating Guardfile\e[0m\e[0m\n\e[1m\e[32mCreating specs/app_spec.coffee\e[0m\e[0m\n\e[1m\e[32mYour Titanium project is ready for you to get rockin!\e[0m\e[0m\n")
69
+ response.should eql("\e[1m\e[32mCreating the tmp directory.\e[0m\e[0m\n\e[1m\e[32mRemoving README file.\e[0m\e[0m\n\e[1m\e[32mRemoving Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/images directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/vendor directory.\e[0m\e[0m\n\e[1m\e[32mCreating the config directory.\e[0m\e[0m\n\e[1m\e[32mCreating the docs directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/stylesheets directory.\e[0m\e[0m\n\e[1m\e[32mCreating the spec/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the spec/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd file.\e[0m\e[0m\n\e[1m\e[32mCreating app/app.coffee\e[0m\e[0m\n\e[1m\e[32mCreating .gitignore\e[0m\e[0m\n\e[1m\e[32mCreating spec/app_spec.coffee\e[0m\e[0m\n\e[1m\e[32mYour Titanium project is ready for you to get rockin!\e[0m\e[0m\n")
74
70
  status.should eql(Ti::CLI::STATUS_TYPES[:success])
75
71
  end
76
72
  after (:all) do
@@ -80,7 +76,7 @@ describe "Ti Generator Commands" do
80
76
  context "with custom name, id and platform (ti new Demo com.mycompany.demo ipad)" do
81
77
  it "should generate new project \"Demo\" with id \"com.mycompany.demo\" and for platform \"ipad\"" do
82
78
  response, status = capture_with_status(:stdout){ Ti::CLI.start(['new', 'Demo', 'com.mycompany.demo']) }
83
- response.should eql("\e[1m\e[32mCreating the tmp directory.\e[0m\e[0m\n\e[1m\e[32mRemoving README file.\e[0m\e[0m\n\e[1m\e[32mRemoving Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/images directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/vendor directory.\e[0m\e[0m\n\e[1m\e[32mCreating the config directory.\e[0m\e[0m\n\e[1m\e[32mCreating the docs directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/stylesheets directory.\e[0m\e[0m\n\e[1m\e[32mCreating the specs/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the specs/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd file.\e[0m\e[0m\n\e[1m\e[32mCreating app/app.coffee\e[0m\e[0m\n\e[1m\e[32mCreating .gitignore\e[0m\e[0m\n\e[1m\e[32mCreating config/config.rb\e[0m\e[0m\n\e[1m\e[32mCreating Rakefile\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd\e[0m\e[0m\n\e[1m\e[32mCreating Guardfile\e[0m\e[0m\n\e[1m\e[32mCreating specs/app_spec.coffee\e[0m\e[0m\n\e[1m\e[32mYour Titanium project is ready for you to get rockin!\e[0m\e[0m\n")
79
+ response.should eql("\e[1m\e[32mCreating the tmp directory.\e[0m\e[0m\n\e[1m\e[32mRemoving README file.\e[0m\e[0m\n\e[1m\e[32mRemoving Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/images directory.\e[0m\e[0m\n\e[1m\e[32mCreating the Resources/vendor directory.\e[0m\e[0m\n\e[1m\e[32mCreating the config directory.\e[0m\e[0m\n\e[1m\e[32mCreating the docs directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating the app/demo/stylesheets directory.\e[0m\e[0m\n\e[1m\e[32mCreating the spec/models directory.\e[0m\e[0m\n\e[1m\e[32mCreating the spec/views directory.\e[0m\e[0m\n\e[1m\e[32mCreating Readme.mkd file.\e[0m\e[0m\n\e[1m\e[32mCreating app/app.coffee\e[0m\e[0m\n\e[1m\e[32mCreating .gitignore\e[0m\e[0m\n\e[1m\e[32mCreating spec/app_spec.coffee\e[0m\e[0m\n\e[1m\e[32mYour Titanium project is ready for you to get rockin!\e[0m\e[0m\n")
84
80
  status.should eql(Ti::CLI::STATUS_TYPES[:success])
85
81
  end
86
82
  after (:all) do
@@ -0,0 +1,34 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ti:app xmlns:ti="http://ti.appcelerator.org">
3
+ <id>com.mycompany.demo</id>
4
+ <name>Demo</name>
5
+ <version>1.0</version>
6
+ <publisher>Rupak Ganguly</publisher>
7
+ <url>www.mycompany.com</url>
8
+ <description>The Demo project.</description>
9
+ <copyright>2011 by Rupak Ganguly</copyright>
10
+ <icon>default_app_logo.png</icon>
11
+ <persistent-wifi>false</persistent-wifi>
12
+ <prerendered-icon>false</prerendered-icon>
13
+ <statusbar-style>default</statusbar-style>
14
+ <statusbar-hidden>false</statusbar-hidden>
15
+ <fullscreen>false</fullscreen>
16
+ <navbar-hidden>false</navbar-hidden>
17
+ <analytics>true</analytics>
18
+ <guid>057a668a-a9f1-4616-b66d-dd6002212f18</guid>
19
+ <iphone>
20
+ <orientations device="iphone">
21
+ <orientation>Ti.UI.PORTRAIT</orientation>
22
+ </orientations>
23
+ <orientations device="ipad">
24
+ <orientation>Ti.UI.PORTRAIT</orientation>
25
+ <orientation>Ti.UI.UPSIDE_PORTRAIT</orientation>
26
+ <orientation>Ti.UI.LANDSCAPE_LEFT</orientation>
27
+ <orientation>Ti.UI.LANDSCAPE_RIGHT</orientation>
28
+ </orientations>
29
+ </iphone>
30
+ <android xmlns:android="http://schemas.android.com/apk/res/android">
31
+ </android>
32
+ <modules>
33
+ </modules>
34
+ </ti:app>
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Ti Config" do
4
+ context "Reading the Ti app config file (tiapp.xml)" do
5
+ before (:all) do
6
+ @config = Ti::Config.new
7
+ @config.parse(fixture_file(:config, 'tiapp.xml'))
8
+ end
9
+ it "should be able to get the id" do
10
+ @config.id.should eql("com.mycompany.demo")
11
+ end
12
+ it "should be able to get the name" do
13
+ @config.name.should eql("Demo")
14
+ end
15
+ it "should be able to get the version" do
16
+ @config.version.should eql("1.0")
17
+ end
18
+ it "should be able to get the publisher" do
19
+ @config.publisher.should eql("Rupak Ganguly")
20
+ end
21
+ it "should be able to get the url" do
22
+ @config.url.should eql("www.mycompany.com")
23
+ end
24
+ it "should be able to get the description" do
25
+ @config.description.should eql("The Demo project.")
26
+ end
27
+ it "should be able to get the copyright" do
28
+ @config.copyright.should eql("2011 by Rupak Ganguly")
29
+ end
30
+ end
31
+ context "Write tiapp.xml config file" do
32
+
33
+ end
34
+ end
@@ -2,6 +2,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'ti'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'ti'
5
+ require 'stringio'
6
+ require 'config'
5
7
 
6
8
  RSpec.configure do |config|
7
9
 
@@ -28,4 +30,10 @@ RSpec.configure do |config|
28
30
  FileUtils.rm_rf(project_dir.join(name)) if FileTest.exists?(project_dir.join(name))
29
31
  end
30
32
  end
33
+
34
+ def fixture_file(type, filename)
35
+ dir_name = type.to_s + "s"
36
+ File.dirname(__FILE__) + "/fixtures/#{dir_name}/#{filename}"
37
+ end
38
+
31
39
  end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "Creating of a model" do
4
+ before(:all) do
5
+ ::Ti::Generate::Project.create('dailyfocus', 'org.codewranglers.demo', 'ipad')
6
+ end
7
+
8
+ context "Creating a model file and its spec" do
9
+ before(:all) do
10
+ # ::Ti::Generate::Model.create("user")
11
+ end
12
+
13
+ it "should have created the model coffee-script within the app/models directory" do
14
+ # File.exists?("app/dailyfocus/models/user.coffee").should be_true
15
+ end
16
+
17
+ it "should have created the model coffee-script within the spec/models directory" do
18
+ # File.exists?("spec/models/user_spec.coffee").should be_true
19
+ end
20
+ end
21
+
22
+ after(:all) do
23
+ remove_directories('dailyfocus', 'app', 'spec/models')
24
+ end
25
+ end
@@ -0,0 +1,121 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "Creating of a new Ti Project" do
4
+ before(:all) do
5
+ ::Ti::Generate::Project.create('dailyfocus', 'org.codewranglers.demo', 'ipad')
6
+ end
7
+
8
+ context "Directories should be created" do
9
+
10
+ it "should have created the project" do
11
+ File.directory?("dailyfocus").should be_true
12
+ end
13
+
14
+ it "should have an app directory" do
15
+ File.directory?("dailyfocus/app").should be_true
16
+ end
17
+
18
+ it "should have a config directory" do
19
+ File.directory?("dailyfocus/config").should be_true
20
+ end
21
+
22
+ it "should have a docs directory" do
23
+ File.directory?("dailyfocus/docs").should be_true
24
+ end
25
+
26
+ it "should have a Resources directory" do
27
+ File.directory?("dailyfocus/Resources").should be_true
28
+ end
29
+
30
+ it "should have a specs directory" do
31
+ File.directory?("dailyfocus/spec").should be_true
32
+ end
33
+
34
+ it "should have a tmp directory" do
35
+ File.directory?("dailyfocus/tmp").should be_true
36
+ end
37
+ end
38
+
39
+ context "Top tier files should be created" do
40
+ it "should have created the Guardfile" do
41
+ File.exists?("dailyfocus/Guardfile").should be_true
42
+ end
43
+
44
+ it "should have created the LICENSE" do
45
+ File.exists?("dailyfocus/LICENSE").should be_true
46
+ end
47
+
48
+ it "should have created the Rakefile" do
49
+ File.exists?("dailyfocus/Rakefile").should be_true
50
+ end
51
+
52
+ it "should have created the Readme.mkd" do
53
+ File.exists?("dailyfocus/Readme.mkd").should be_true
54
+ end
55
+
56
+ it "should have created the tiapp.xml" do
57
+ File.exists?("dailyfocus/tiapp.xml").should be_true
58
+ end
59
+ end
60
+
61
+ context "Inside the app directory" do
62
+ it "should have created the app.coffee file" do
63
+ File.exists?("dailyfocus/app/app.coffee").should be_true
64
+ end
65
+
66
+ it "should have created the models directory" do
67
+ File.directory?("dailyfocus/app/dailyfocus/models").should be_true
68
+ end
69
+
70
+ it "should have created the stylesheets directory" do
71
+ File.directory?("dailyfocus/app/dailyfocus/stylesheets").should be_true
72
+ end
73
+
74
+ it "should have created the views directory" do
75
+ File.directory?("dailyfocus/app/dailyfocus/views").should be_true
76
+ end
77
+ end
78
+
79
+ context "Inside the config directory" do
80
+ it "should have created the config.rb file" do
81
+ File.exists?("dailyfocus/config/config.rb").should be_true
82
+ end
83
+ end
84
+
85
+ context "Inside the Resources directory" do
86
+ it "should have created the images directory" do
87
+ File.directory?("dailyfocus/Resources/images").should be_true
88
+ end
89
+
90
+ it "should have created the vendor directory" do
91
+ File.directory?("dailyfocus/Resources/vendor").should be_true
92
+ end
93
+
94
+ it "should have created the KS_nav_ui.png within the images directory" do
95
+ File.exists?("dailyfocus/Resources/images/KS_nav_ui.png").should be_true
96
+ end
97
+
98
+ it "should have created the KS_nav_views.png within the images directory" do
99
+ File.exists?("dailyfocus/Resources/images/KS_nav_views.png").should be_true
100
+ end
101
+ end
102
+
103
+ context "Inside the specs directory" do
104
+ it "should have created the app_spec.coffee file" do
105
+ File.exists?("dailyfocus/spec/app_spec.coffee").should be_true
106
+ end
107
+
108
+ it "should have created the models directory" do
109
+ File.directory?("dailyfocus/spec/models").should be_true
110
+ end
111
+
112
+ it "should have created the views directory" do
113
+ File.directory?("dailyfocus/spec/views").should be_true
114
+ end
115
+
116
+ end
117
+
118
+ after(:all) do
119
+ remove_directories('dailyfocus')
120
+ end
121
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "Creating of a view file" do
4
+ before(:each) do
5
+ ::Ti::Generate::Project.create('dailyfocus', 'org.codewranglers.demo', 'ipad')
6
+ end
7
+
8
+ context "Creating a view file and its spec" do
9
+ before(:all) do
10
+ # system("cd dailyfocus && ti g view user")
11
+ end
12
+
13
+ it "should have created the view coffee-script within the app/views directory" do
14
+ # File.exists?("app/dailyfocus/views/user.coffee").should be_true
15
+ end
16
+
17
+ it "should have created the view coffee-script within the spec/views directory" do
18
+ # File.exists?("spec/views/user_spec.coffee").should be_true
19
+ end
20
+ end
21
+
22
+ after(:all) do
23
+ remove_directories('dailyfocus', 'app', 'spec/views')
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "The Logger" do
4
+ before(:each) do
5
+ @stdout_orig = $stdout
6
+ $stdout = StringIO.new
7
+
8
+ @stderr_orig = $stderr
9
+ $stderr = StringIO.new
10
+ end
11
+
12
+ context "Reporting an error" do
13
+ it "should output a formatted message with a red color" do
14
+ Ti::Logger.error("This is failing.")
15
+ $stderr.string.should == "\e[1m\e[31mThis is failing.\e[0m\e[0m\n"
16
+ end
17
+ end
18
+
19
+ context "Reporting back a success" do
20
+ it "should output a formatted message with a green color" do
21
+ Ti::Logger.report("This is a success.")
22
+ $stdout.string.should == "\e[1m\e[32mThis is a success.\e[0m\e[0m\n"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,120 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "The utilities" do
4
+
5
+ before(:each) do
6
+ class Klass
7
+ class << self
8
+ include ::Ti::Utils
9
+ end
10
+ end
11
+ end
12
+
13
+ it "should return the base location" do
14
+ Klass.base_location.should == Pathname.new(Dir.pwd)
15
+ end
16
+
17
+ it "should have the base location alias, location return the base location" do
18
+ Klass.location.should == Pathname.new(Dir.pwd)
19
+ end
20
+
21
+ context "Creating new files and deleting them" do
22
+ it "should create a new file" do
23
+ Klass.create_new_file("DEMO")
24
+ File.exists?(Pathname.new(Dir.pwd).join("DEMO")).should be_true
25
+ end
26
+
27
+ it "should delete the new file" do
28
+ Klass.remove_files("DEMO")
29
+ File.exists?(Pathname.new(Dir.pwd).join("DEMO")).should be_false
30
+ end
31
+
32
+ after(:all) do
33
+ remove_directories("DEMO")
34
+ end
35
+ end
36
+
37
+ context "Touching files into existence like no one has touched a file before" do
38
+ it "should come alive!!" do
39
+ Klass.touch("File", "into", "existence")
40
+ File.exists?(Pathname.new(Dir.pwd).join("File")).should be_true
41
+ File.exists?(Pathname.new(Dir.pwd).join("into")).should be_true
42
+ File.exists?(Pathname.new(Dir.pwd).join("existence")).should be_true
43
+ end
44
+
45
+ after(:all) do
46
+ remove_directories("File", "into", "existence")
47
+ end
48
+ end
49
+
50
+ # context "Creating Model Files and their spec files" do
51
+ # it "should create the model directory" do
52
+ # Klass.create_model_file("user")
53
+ # File.directory?(Pathname.new(Dir.pwd).join("app/models")).should be_true
54
+ # File.exists?(Pathname.new(Dir.pwd).join("app/models/user.coffee")).should be_true
55
+ # File.exists?(Pathname.new(Dir.pwd).join("spec/models/user_spec.coffee")).should be_true
56
+ # end
57
+ #
58
+ # after(:all) do
59
+ # remove_directories('app', 'spec/views', 'spec/models')
60
+ # end
61
+ # end
62
+ #
63
+ # context "Creating View Files and their spec files" do
64
+ # it "should create the model directory" do
65
+ # Klass.create_view_file("user")
66
+ # File.directory?(Pathname.new(Dir.pwd).join("app/views")).should be_true
67
+ # File.exists?(Pathname.new(Dir.pwd).join("app/views/user.coffee")).should be_true
68
+ # File.exists?(Pathname.new(Dir.pwd).join("spec/views/user_spec.coffee")).should be_true
69
+ # end
70
+ #
71
+ # after(:all) do
72
+ # remove_directories('app', 'spec/views', 'spec/models')
73
+ # end
74
+ # end
75
+
76
+ context "Creating and deleting directories" do
77
+ it "should create some directories" do
78
+ Klass.create_directories("Dude", "looks", "like", "a", "lady")
79
+ File.exists?(Pathname.new(Dir.pwd).join("Dude")).should be_true
80
+ File.exists?(Pathname.new(Dir.pwd).join("looks")).should be_true
81
+ File.exists?(Pathname.new(Dir.pwd).join("like")).should be_true
82
+ File.exists?(Pathname.new(Dir.pwd).join("a")).should be_true
83
+ File.exists?(Pathname.new(Dir.pwd).join("lady")).should be_true
84
+ end
85
+
86
+ it "should delete the created directories" do
87
+ Klass.remove_directories("Dude", "looks", "like", "a", "lady")
88
+ File.exists?(Pathname.new(Dir.pwd).join("Dude")).should be_false
89
+ File.exists?(Pathname.new(Dir.pwd).join("looks")).should be_false
90
+ File.exists?(Pathname.new(Dir.pwd).join("like")).should be_false
91
+ File.exists?(Pathname.new(Dir.pwd).join("a")).should be_false
92
+ File.exists?(Pathname.new(Dir.pwd).join("lady")).should be_false
93
+ end
94
+
95
+ after(:all) do
96
+ remove_directories("Dude", "looks", "like", "a", "lady")
97
+ end
98
+ end
99
+
100
+ context "Test the Utils logging" do
101
+ before(:each) do
102
+ @stdout_orig = $stdout
103
+ $stdout = StringIO.new
104
+
105
+ @stderr_orig = $stderr
106
+ $stderr = StringIO.new
107
+ end
108
+
109
+ it "should log the error" do
110
+ Klass.error("Failed")
111
+ $stderr.string.should == "\e[1m\e[31mFailed\e[0m\e[0m\n"
112
+ end
113
+
114
+ it "should log the success" do
115
+ Klass.log("Success")
116
+ $stdout.string.should == "\e[1m\e[32mSuccess\e[0m\e[0m\n"
117
+ end
118
+ end
119
+
120
+ end