jpmobile 0.0.8 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +0 -3
  2. data/{spec/spec.opts → .rspec} +1 -2
  3. data/README.rdoc +122 -128
  4. data/Rakefile +23 -101
  5. data/VERSION.yml +4 -3
  6. data/jpmobile.gemspec +130 -182
  7. data/lib/jpmobile.rb +37 -24
  8. data/lib/jpmobile/docomo_guid.rb +2 -1
  9. data/lib/jpmobile/email.rb +3 -4
  10. data/lib/jpmobile/emoticon.rb +2 -6
  11. data/lib/jpmobile/encoding.rb +29 -0
  12. data/lib/jpmobile/filter.rb +42 -134
  13. data/lib/jpmobile/helpers.rb +5 -18
  14. data/lib/jpmobile/hook_action_controller.rb +24 -16
  15. data/lib/jpmobile/hook_action_view.rb +28 -89
  16. data/lib/jpmobile/mobile/abstract_mobile.rb +21 -4
  17. data/lib/jpmobile/mobile/android.rb +10 -0
  18. data/lib/jpmobile/mobile/au.rb +28 -3
  19. data/lib/jpmobile/mobile/ddipocket.rb +12 -0
  20. data/lib/jpmobile/mobile/display.rb +29 -26
  21. data/lib/jpmobile/mobile/docomo.rb +38 -12
  22. data/lib/jpmobile/mobile/iphone.rb +26 -0
  23. data/lib/jpmobile/mobile/smart_phone.rb +21 -0
  24. data/lib/jpmobile/mobile/softbank.rb +16 -41
  25. data/lib/jpmobile/mobile/vodafone.rb +17 -0
  26. data/lib/jpmobile/mobile/willcom.rb +1 -10
  27. data/lib/jpmobile/mobile/windows_phone.rb +10 -0
  28. data/lib/jpmobile/position.rb +4 -3
  29. data/lib/jpmobile/rack.rb +43 -0
  30. data/lib/jpmobile/rack/filter.rb +51 -0
  31. data/lib/jpmobile/rack/mobile_carrier.rb +33 -0
  32. data/lib/jpmobile/rack/params_filter.rb +47 -0
  33. data/lib/jpmobile/rails.rb +22 -0
  34. data/lib/jpmobile/request_with_mobile.rb +8 -12
  35. data/lib/jpmobile/trans_sid.rb +44 -26
  36. data/lib/jpmobile/util.rb +68 -0
  37. data/{tasks → lib/tasks}/jpmobile_tasks.rake +32 -13
  38. data/spec/rack/jpmobile/android_spec.rb +20 -0
  39. data/spec/rack/jpmobile/au_spec.rb +206 -0
  40. data/spec/rack/jpmobile/docomo_spec.rb +237 -0
  41. data/spec/rack/jpmobile/emoticon_spec.rb +215 -0
  42. data/spec/rack/jpmobile/filter_spec.rb +181 -0
  43. data/spec/rack/jpmobile/iphone_spec.rb +32 -0
  44. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +39 -0
  45. data/spec/rack/jpmobile/params_filter_spec.rb +193 -0
  46. data/spec/rack/jpmobile/softbank_spec.rb +123 -0
  47. data/spec/rack/jpmobile/willcom_spec.rb +67 -0
  48. data/spec/rack/jpmobile/windows_phone.rb +20 -0
  49. data/spec/rack_helper.rb +86 -0
  50. data/spec/spec_helper.rb +3 -2
  51. data/spec/unit/detect_by_email_spec.rb +21 -27
  52. data/spec/unit/is_carrier_spec.rb +56 -84
  53. data/spec/unit/spec_helper.rb +1 -2
  54. data/spec/unit/util_spec.rb +2 -2
  55. data/spec/unit/valid_ip_spec.rb +43 -52
  56. data/test/legacy/autoload_test.rb +1 -3
  57. data/test/legacy/emoticon_test.rb +5 -6
  58. data/test/legacy/helper.rb +0 -71
  59. data/test/rails/overrides/.rspec +5 -0
  60. data/test/rails/overrides/Gemfile +32 -0
  61. data/test/rails/overrides/app/controllers/docomo_guid_always_controller.rb +3 -0
  62. data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +5 -0
  63. data/test/rails/overrides/app/controllers/docomo_guid_docomo_controller.rb +3 -0
  64. data/test/rails/overrides/app/controllers/filter_controller.rb +0 -34
  65. data/test/rails/overrides/app/controllers/filter_controller_base.rb +19 -0
  66. data/test/rails/overrides/app/controllers/hankaku_filter_controller.rb +3 -0
  67. data/test/rails/overrides/app/controllers/links_controller.rb +28 -0
  68. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
  69. data/test/rails/overrides/app/controllers/template_path_controller.rb +3 -0
  70. data/test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb +4 -0
  71. data/test/rails/overrides/app/controllers/trans_sid_always_controller.rb +3 -0
  72. data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -0
  73. data/test/rails/overrides/app/controllers/trans_sid_mobile_controller.rb +3 -0
  74. data/test/rails/overrides/app/controllers/trans_sid_none_controller.rb +3 -0
  75. data/test/rails/overrides/app/views/links/au_gps.html.erb +1 -0
  76. data/test/rails/overrides/app/views/links/au_location.html.erb +1 -0
  77. data/test/rails/overrides/app/views/links/docomo_foma_gps.html.erb +1 -0
  78. data/test/rails/overrides/app/views/links/docomo_openiarea.html.erb +1 -0
  79. data/test/rails/overrides/app/views/links/docomo_utn.html.erb +1 -0
  80. data/test/rails/overrides/app/views/links/link.html.erb +1 -0
  81. data/test/rails/overrides/app/views/links/show_all.html.erb +1 -0
  82. data/test/rails/overrides/app/views/links/softbank_location.html.erb +1 -0
  83. data/test/rails/overrides/app/views/links/willcom_location.html.erb +1 -0
  84. data/test/rails/overrides/app/views/template_path/_partial_smart_phone.html.erb +1 -0
  85. data/test/rails/overrides/app/views/template_path/_partial_smart_phone_iphone.html.erb +1 -0
  86. data/test/rails/overrides/app/views/template_path/index_smart_phone.html.erb +1 -0
  87. data/test/rails/overrides/app/views/template_path/index_smart_phone_iphone.html.erb +1 -0
  88. data/test/rails/overrides/app/views/template_path/show_mobile.html.erb +1 -0
  89. data/test/rails/overrides/app/views/template_path/show_mobile_docomo.html.erb +1 -0
  90. data/test/rails/overrides/autotest/discover.rb +2 -0
  91. data/test/rails/overrides/config/initializers/jpmobile_generator.rb +1 -0
  92. data/test/rails/overrides/config/routes.rb +58 -0
  93. data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +16 -0
  94. data/test/rails/overrides/spec/helpers/helpers_spec.rb +2 -2
  95. data/test/rails/overrides/spec/{controllers → requests}/docomo_guid_spec.rb +37 -14
  96. data/test/rails/overrides/spec/{controllers → requests}/docomo_spec.rb +11 -8
  97. data/test/rails/overrides/spec/{controllers → requests}/emobile_spec.rb +24 -8
  98. data/test/rails/overrides/spec/requests/filter_spec.rb +171 -0
  99. data/test/rails/overrides/spec/requests/helpers_spec.rb +187 -0
  100. data/test/rails/overrides/spec/requests/pc_spec.rb +22 -0
  101. data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +21 -0
  102. data/test/rails/overrides/spec/requests/template_path_spec.rb +234 -0
  103. data/test/rails/overrides/spec/requests/trans_sid_spec.rb +142 -0
  104. data/test/rails/overrides/spec/spec_helper.rb +17 -48
  105. data/test/sinatra/guestbook.rb +40 -0
  106. data/test/sinatra/test/filter_test.rb +39 -0
  107. metadata +185 -312
  108. data/lib/jpmobile/hook_request.rb +0 -5
  109. data/lib/jpmobile/rack/auth.rb +0 -55
  110. data/lib/jpmobile/rack/combined_logger.rb +0 -54
  111. data/lib/jpmobile/rack/request.rb +0 -7
  112. data/lib/jpmobile/rack/trans_sid.rb +0 -14
  113. data/lib/jpmobile/version.rb +0 -9
  114. data/spec/unit/detect_by_ua_spec.rb +0 -40
  115. data/test/legacy/au_test.rb +0 -173
  116. data/test/legacy/docomo_test.rb +0 -187
  117. data/test/legacy/emoticon_functional_test.rb +0 -195
  118. data/test/legacy/filter_test.rb +0 -34
  119. data/test/legacy/helpers_test.rb +0 -217
  120. data/test/legacy/softbank_test.rb +0 -183
  121. data/test/legacy/willcom_test.rb +0 -56
  122. data/test/rails/2.3.2/spec/controllers/trans_sid_spec.rb +0 -99
  123. data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +0 -13
  124. data/test/rails/overrides/app/controllers/trans_sid_controller.rb +0 -28
  125. data/test/rails/overrides/lib/tasks/rspec.rake +0 -165
  126. data/test/rails/overrides/spec/controllers/filter_spec.rb +0 -159
  127. data/test/rails/overrides/spec/controllers/pc_spec.rb +0 -13
  128. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +0 -42
  129. data/test/rails/overrides/spec/controllers/template_path_spec.rb +0 -117
  130. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +0 -117
  131. data/test/rails/overrides/spec/rspec.rake +0 -165
  132. data/test/rails/overrides/spec/spec.opts +0 -4
@@ -1,13 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- describe "PCからのアクセスの場合", :behaviour_type=>:controller do
6
- controller_name :mobile_spec
7
- it "request.mobile は nil であるべき" do
8
- request.mobile.should be_nil
9
- end
10
- it "request.mobile? は false であるべき" do
11
- request.mobile?.should be_false
12
- end
13
- end
@@ -1,42 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- describe "携帯電話からのアクセス", :shared => true do
6
- it "request.mobile? は true であること" do
7
- request.mobile?.should be_true
8
- end
9
- end
10
-
11
- describe "Softbank Emulator からのアクセスのとき", :behaviour_type=>:controller do
12
- before do
13
- request.user_agent = "Semulator"
14
- end
15
- controller_name :mobile_spec
16
- it "request.mobile は Softbank のインスタンスであること" do
17
- request.mobile.should be_an_instance_of(Jpmobile::Mobile::Softbank)
18
- end
19
- it_should_behave_like "携帯電話からのアクセス"
20
- end
21
-
22
- describe "Vodafone Emulator からのアクセスのとき", :behaviour_type=>:controller do
23
- before do
24
- request.user_agent = "Vemulator"
25
- end
26
- controller_name :mobile_spec
27
- it "request.mobile は Vodafone のインスタンスであること" do
28
- request.mobile.should be_an_instance_of(Jpmobile::Mobile::Vodafone)
29
- end
30
- it_should_behave_like "携帯電話からのアクセス"
31
- end
32
-
33
- describe "J-PHONE Emulator からのアクセスのとき", :behaviour_type=>:controller do
34
- before do
35
- request.user_agent = "J-EMULATOR"
36
- end
37
- controller_name :mobile_spec
38
- it "request.mobile は Jphone のインスタンスであること" do
39
- request.mobile.should be_an_instance_of(Jpmobile::Mobile::Jphone)
40
- end
41
- it_should_behave_like "携帯電話からのアクセス"
42
- end
@@ -1,117 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- #
6
- # 携帯からのアクセス
7
- #
8
- describe TemplatePathController, "DoCoMo SH902i からのアクセス" do
9
- before do
10
- request.user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
11
- get :index
12
- end
13
-
14
- it 'テンプレートの探索順が正しいこと' do
15
- response.template.mobile_template_candidates.should == [ 'mobile_docomo', 'mobile' ]
16
- end
17
- end
18
-
19
- describe TemplatePathController, "au CA32 からのアクセス" do
20
- before do
21
- request.user_agent = "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
22
- get :index
23
- end
24
- it 'テンプレートの探索順が正しいこと' do
25
- response.template.mobile_template_candidates.should == [ 'mobile_au', 'mobile' ]
26
- end
27
- end
28
-
29
- describe TemplatePathController, "J-PHONE V401SH からのアクセス" do
30
- before do
31
- request.user_agent = "J-PHONE/3.0/V401SH"
32
- get :index
33
- end
34
- it 'テンプレートの探索順が正しいこと' do
35
- response.template.mobile_template_candidates.should == [ 'mobile_jphone', 'mobile_vodafone', 'mobile_softbank', 'mobile' ]
36
- end
37
- end
38
-
39
- describe TemplatePathController, "Vodafone V903T からのアクセス" do
40
- before do
41
- request.user_agent = "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0"
42
- get :index
43
- end
44
- it 'テンプレートの探索順が正しいこと' do
45
- response.template.mobile_template_candidates.should == [ 'mobile_vodafone', 'mobile_softbank', 'mobile' ]
46
- end
47
- end
48
-
49
- describe TemplatePathController, "SoftBank 910T からのアクセス" do
50
- before do
51
- request.user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
52
- get :index
53
- end
54
- it 'テンプレートの探索順が正しいこと' do
55
- response.template.mobile_template_candidates.should == [ 'mobile_softbank', 'mobile' ]
56
- end
57
- end
58
-
59
- describe TemplatePathController, "integrated_views" do
60
- integrate_views
61
- describe "index" do
62
- context "PCからのアクセスの場合" do
63
- before do
64
- get :index
65
- end
66
- it 'index.html.erbが使用されること' do
67
- response.should have_tag("h1", "index.html.erb")
68
- end
69
- end
70
- context "DoCoMoからのアクセスの場合" do
71
- before do
72
- request.user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
73
- get :index
74
- end
75
- it 'index_mobile_docomo.html.erbが使用されること' do
76
- response.should have_tag("h1", "index_mobile_docomo.html.erb")
77
- end
78
- end
79
- context "SoftBankからのアクセスの場合" do
80
- before do
81
- request.user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
82
- get :index
83
- end
84
- it 'index_mobile.html.erbが使用されること' do
85
- response.should have_tag("h1", "index_mobile.html.erb")
86
- end
87
- end
88
- end
89
- describe "partial" do
90
- context "PCからのアクセスの場合" do
91
- before do
92
- get :partial
93
- end
94
- it '_partial.html.erbが使用されること' do
95
- response.should have_tag("h2", "_partial.html.erb")
96
- end
97
- end
98
- context "DoCoMoからのアクセスの場合" do
99
- before do
100
- request.user_agent = "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
101
- get :partial
102
- end
103
- it '_partial_mobile_docomo.html.erbが使用されること' do
104
- response.should have_tag("h2", "_partial_mobile_docomo.html.erb")
105
- end
106
- end
107
- context "SoftBankからのアクセスの場合" do
108
- before do
109
- request.user_agent = "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
110
- get :partial
111
- end
112
- it '_partial_mobile.html.erbが使用されること' do
113
- response.should have_tag("h2", "_partial_mobile.html.erb")
114
- end
115
- end
116
- end
117
- end
@@ -1,117 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__) + '/../spec_helper'
4
-
5
- describe "trans_sid が起動しないとき", :shared => true do
6
- it "で link_to の自動書き換えが行われない" do
7
- get :link
8
- response.body.should =~ %r{^<a href="/.+?/link">linkto</a>$}
9
- end
10
- it "で form の自動書き換えが行われない" do
11
- get :form
12
- response.body.should =~ %r{^<form action="/.+?/form" method="post">Hello</form>$}
13
- end
14
- it "で redirect の自動書き換えが行われない" do
15
- get :redirect
16
- response.should redirect_to('/')
17
- end
18
- end
19
-
20
- describe "trans_sid が起動するとき", :shared => true do
21
- before :each do
22
- request.session_options[:id] = "mysessionid"
23
- end
24
- it "で link_to の自動書き換えが行われる" do
25
- get :link
26
- response.body.should =~ %r{^<a href="/.+?/link\?_session_id=mysessionid">linkto</a>$}
27
- end
28
- it "で form の自動書き換えが行われる" do
29
- get :form
30
- response.body.should =~ %r{^<form action="/.+?/form\?_session_id=mysessionid" method="post">Hello<input type="hidden" name="_session_id" value="mysessionid" /></form>$}
31
- end
32
- it "で redirect の自動書き換えが行われる" do
33
- get :redirect
34
- response.should redirect_to('/?_session_id=mysessionid')
35
- end
36
- it "でセッションIDが空のときには有効にならない" do
37
- request.session_options[:id] = ""
38
- get :link
39
- response.body.should =~ %r{^<a href="/.+?/link">linkto</a>$}
40
- end
41
- end
42
-
43
- describe TransSidBaseController, "という trans_sid が有効になっていないコントローラ" do
44
- controller_name :trans_sid_base
45
- it "の trans_sid_mode は nil" do
46
- controller.trans_sid_mode.should be_nil
47
- end
48
- it_should_behave_like "trans_sid が起動しないとき"
49
- end
50
-
51
- describe TransSidNoneController, "という trans_sid :none が指定されているコントローラ" do
52
- controller_name :trans_sid_none
53
- it "の trans_sid_mode は :none" do
54
- controller.trans_sid_mode.should == :none
55
- end
56
- it_should_behave_like "trans_sid が起動しないとき"
57
- end
58
-
59
- describe TransSidAlwaysController, "という trans_sid :always が指定されているコントローラ" do
60
- controller_name :trans_sid_always
61
- before :each do
62
- request.session_options[:id] = "mysessionid"
63
- end
64
- it "の trans_sid_mode は :always" do
65
- controller.trans_sid_mode.should == :always
66
- end
67
- it_should_behave_like "trans_sid が起動するとき"
68
- end
69
-
70
- describe TransSidMobileController, "という trans_sid :mobile が指定されているコントローラ" do
71
- controller_name :trans_sid_mobile
72
- it "の trans_sid_mode は :mobile" do
73
- controller.trans_sid_mode.should == :mobile
74
- end
75
- end
76
-
77
- def describe_mobile_with_ua(user_agent, &block)
78
- describe("trans_sid :mobile が指定されているコントローラに #{user_agent} からアクセスしたとき") do
79
- controller_name :trans_sid_mobile
80
- before do
81
- request.user_agent = user_agent
82
- end
83
- instance_eval(&block)
84
- end
85
- end
86
-
87
- describe TransSidAlwaysController, "という trans_sid :always が指定されているコントローラで reset_session したとき" do
88
- controller_name :trans_sid_always
89
- before :each do
90
- # 擬似的 reset_session
91
- request.session_options[:id] = nil
92
- end
93
- it "の trans_sid_mode は :always" do
94
- controller.trans_sid_mode.should == :always
95
- end
96
- it_should_behave_like "trans_sid が起動しないとき"
97
- end
98
-
99
- describe_mobile_with_ua "DoCoMo/2.0 SH902i(c100;TB;W24H12)" do
100
- it_should_behave_like "trans_sid が起動するとき"
101
- end
102
-
103
- describe_mobile_with_ua "J-PHONE/3.0/V301D" do
104
- it_should_behave_like "trans_sid が起動するとき"
105
- end
106
-
107
- describe_mobile_with_ua "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0" do
108
- it_should_behave_like "trans_sid が起動しないとき"
109
- end
110
-
111
- describe_mobile_with_ua "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1" do
112
- it_should_behave_like "trans_sid が起動しないとき"
113
- end
114
-
115
- describe_mobile_with_ua "Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0" do
116
- it_should_behave_like "trans_sid が起動しないとき"
117
- end
@@ -1,165 +0,0 @@
1
- gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
2
-
3
- # Don't load rspec if running "rake gems:*"
4
- unless ARGV.any? {|a| a =~ /^gems/}
5
-
6
- begin
7
- require 'spec/rake/spectask'
8
- rescue MissingSourceFile
9
- module Spec
10
- module Rake
11
- class SpecTask
12
- def initialize(name)
13
- task name do
14
- # if rspec-rails is a configured gem, this will output helpful material and exit ...
15
- require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
16
-
17
- # ... otherwise, do this:
18
- raise <<-MSG
19
-
20
- #{"*" * 80}
21
- * You are trying to run an rspec rake task defined in
22
- * #{__FILE__},
23
- * but rspec can not be found in vendor/gems, vendor/plugins or system gems.
24
- #{"*" * 80}
25
- MSG
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
32
-
33
- Rake.application.instance_variable_get('@tasks').delete('default')
34
-
35
- spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
36
- task :noop do
37
- end
38
-
39
- task :default => :spec
40
- task :stats => "spec:statsetup"
41
-
42
- desc "Run all specs in spec directory (excluding plugin specs)"
43
- Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
44
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
45
- t.spec_files = FileList['spec/**/*/*_spec.rb']
46
- end
47
-
48
- namespace :spec do
49
- desc "Run all specs in spec directory with RCov (excluding plugin specs)"
50
- Spec::Rake::SpecTask.new(:rcov) do |t|
51
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
52
- t.spec_files = FileList['spec/**/*/*_spec.rb']
53
- t.rcov = true
54
- t.rcov_opts = lambda do
55
- IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
56
- end
57
- end
58
-
59
- desc "Print Specdoc for all specs (excluding plugin specs)"
60
- Spec::Rake::SpecTask.new(:doc) do |t|
61
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
62
- t.spec_files = FileList['spec/**/*/*_spec.rb']
63
- end
64
-
65
- desc "Print Specdoc for all plugin examples"
66
- Spec::Rake::SpecTask.new(:plugin_doc) do |t|
67
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
68
- t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*')
69
- end
70
-
71
- [:models, :controllers, :views, :helpers, :lib].each do |sub|
72
- desc "Run the code examples in spec/#{sub}"
73
- Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
74
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
75
- t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
76
- end
77
- end
78
-
79
- desc "Run the code examples in vendor/plugins (except RSpec's own)"
80
- Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
81
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
82
- t.spec_files = FileList['vendor/plugins/**/spec/**/*/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
83
- end
84
-
85
- namespace :plugins do
86
- desc "Runs the examples for rspec_on_rails"
87
- Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
88
- t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
89
- t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*/*_spec.rb']
90
- end
91
- end
92
-
93
- # Setup specs for stats
94
- task :statsetup do
95
- require 'code_statistics'
96
- ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
97
- ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
98
- ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
99
- ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
100
- ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
101
- ::STATS_DIRECTORIES << %w(Routing\ specs spec/lib) if File.exist?('spec/routing')
102
- ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
103
- ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
104
- ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
105
- ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
106
- ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
107
- ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
108
- end
109
-
110
- namespace :db do
111
- namespace :fixtures do
112
- desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z."
113
- task :load => :environment do
114
- ActiveRecord::Base.establish_connection(Rails.env)
115
- base_dir = File.join(Rails.root, 'spec', 'fixtures')
116
- fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir, ENV['FIXTURES_DIR']) : base_dir
117
-
118
- require 'active_record/fixtures'
119
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f| File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir, '*.{yml,csv}'))).each do |fixture_file|
120
- Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
121
- end
122
- end
123
- end
124
- end
125
-
126
- namespace :server do
127
- daemonized_server_pid = File.expand_path("#{RAILS_ROOT}/tmp/pids/spec_server.pid")
128
-
129
- desc "start spec_server."
130
- task :start do
131
- if File.exist?(daemonized_server_pid)
132
- $stderr.puts "spec_server is already running."
133
- else
134
- $stderr.puts %Q{Starting up spec_server ...}
135
- FileUtils.mkdir_p('tmp/pids') unless test ?d, 'tmp/pids'
136
- system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
137
- end
138
- end
139
-
140
- desc "stop spec_server."
141
- task :stop do
142
- unless File.exist?(daemonized_server_pid)
143
- $stderr.puts "No server running."
144
- else
145
- $stderr.puts "Shutting down spec_server ..."
146
- system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
147
- File.delete(daemonized_server_pid)
148
- end
149
- end
150
-
151
- desc "restart spec_server."
152
- task :restart => [:stop, :start]
153
-
154
- desc "check if spec server is running"
155
- task :status do
156
- if File.exist?(daemonized_server_pid)
157
- $stderr.puts %Q{spec_server is running (PID: #{File.read(daemonized_server_pid).gsub("\n","")})}
158
- else
159
- $stderr.puts "No server running."
160
- end
161
- end
162
- end
163
- end
164
-
165
- end