smalruby-editor 0.0.8-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of smalruby-editor might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +4 -0
- data/.rubocop.yml +19 -0
- data/.ruby-version +1 -0
- data/.simplecov +7 -0
- data/.travis.yml +23 -0
- data/LEGAL +13 -0
- data/LICENSE +22 -0
- data/Procfile +1 -0
- data/README.rdoc +46 -0
- data/Rakefile +9 -0
- data/app/assets/images/.keep +0 -0
- data/app/assets/images/favicon.ico +0 -0
- data/app/assets/javascripts/application.js +21 -0
- data/app/assets/javascripts/editor.js.coffee.erb +139 -0
- data/app/assets/stylesheets/application.css +19 -0
- data/app/assets/stylesheets/editor.css.scss +19 -0
- data/app/assets/stylesheets/flatstrap-custom.css.scss +2 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/concerns/.keep +0 -0
- data/app/controllers/editor_controller.rb +5 -0
- data/app/controllers/source_codes_controller.rb +106 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/editor_helper.rb +2 -0
- data/app/mailers/.keep +0 -0
- data/app/models/.keep +0 -0
- data/app/models/concerns/.keep +0 -0
- data/app/models/source_code.rb +49 -0
- data/app/views/editor/index.html.erb +23 -0
- data/app/views/layouts/application.html.erb +15 -0
- data/bin/bundle +3 -0
- data/bin/rails +4 -0
- data/bin/rake +4 -0
- data/bin/smalruby-editor +80 -0
- data/config/application.rb +16 -0
- data/config/boot.rb +17 -0
- data/config/database.yml.mysql2 +48 -0
- data/config/database.yml.sqlite3 +31 -0
- data/config/database.yml.travis +5 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +30 -0
- data/config/environments/production.rb +86 -0
- data/config/environments/standalone.rb +16 -0
- data/config/environments/test.rb +46 -0
- data/config/initializers/backtrace_silencers.rb +9 -0
- data/config/initializers/filter_parameter_logging.rb +4 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/secret_token.rb +17 -0
- data/config/initializers/session_store.rb +4 -0
- data/config/initializers/wrap_parameters.rb +15 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +68 -0
- data/config/unicorn.rb +23 -0
- data/config.ru +4 -0
- data/db/migrate/20131216121603_create_source_codes.rb +9 -0
- data/db/migrate/20131219045113_add_filename_to_source_code.rb +5 -0
- data/db/schema.rb +23 -0
- data/db/seeds.rb +7 -0
- data/lib/assets/.keep +0 -0
- data/lib/smalruby_editor/version.rb +3 -0
- data/lib/smalruby_editor.rb +46 -0
- data/lib/tasks/.keep +0 -0
- data/lib/tasks/gem.rake +10 -0
- data/lib/tasks/rspec.rake +16 -0
- data/lib/tasks/rubocop.rake +3 -0
- data/log/.keep +0 -0
- data/public/404.html +58 -0
- data/public/422.html +58 -0
- data/public/500.html +57 -0
- data/public/assets/application-759ce4d1ac1e0e3991e6d350c8f98fc5.js +5267 -0
- data/public/assets/application-759ce4d1ac1e0e3991e6d350c8f98fc5.js.gz +0 -0
- data/public/assets/application-f51ea0e777d97f12a8ce84308f31eb57.css +4791 -0
- data/public/assets/application-f51ea0e777d97f12a8ce84308f31eb57.css.gz +0 -0
- data/public/assets/favicon-c7ae857bb9d06de8742ae2d337157e83.ico +0 -0
- data/public/assets/loading-e8e6dd7833131c92a6c3b9c8ccc6a6ac.gif +0 -0
- data/public/assets/manifest-f86249f9779f8f4d7c8fc148e4361b4f.json +1 -0
- data/public/assets/progressbar-82023a146fba2a0f6d925629ed2b09c5.gif +0 -0
- data/public/favicon.ico +0 -0
- data/public/fonts/FontAwesome.otf +0 -0
- data/public/fonts/fontawesome-webfont.eot +0 -0
- data/public/fonts/fontawesome-webfont.ttf +0 -0
- data/public/fonts/fontawesome-webfont.woff +0 -0
- data/public/robots.txt +5 -0
- data/smalruby-editor.gemspec +81 -0
- data/spec/acceptance/readme.md +3 -0
- data/spec/acceptance/standalone/save.feature +32 -0
- data/spec/acceptance/text_editor/base.feature +24 -0
- data/spec/acceptance/text_editor/check.feature +25 -0
- data/spec/acceptance/text_editor/load.feature +81 -0
- data/spec/acceptance/text_editor/save.feature +34 -0
- data/spec/controllers/editor_controller_spec.rb +12 -0
- data/spec/controllers/source_codes_controller_spec.rb +469 -0
- data/spec/fixtures/files/01.rb +57 -0
- data/spec/fixtures/files/favicon.ico +0 -0
- data/spec/helpers/editor_helper_spec.rb +14 -0
- data/spec/lib/smalruby_editor_spec.rb +66 -0
- data/spec/models/source_code_spec.rb +55 -0
- data/spec/spec_helper.rb +156 -0
- data/spec/steps/ace_steps.rb +59 -0
- data/spec/steps/global_variable.rb +39 -0
- data/spec/steps/text_editor_steps.rb +183 -0
- data/spec/support/assets.rb +18 -0
- data/spec/support/capybara.rb +17 -0
- data/spec/support/env.rb +15 -0
- data/spec/turnip_helper.rb +2 -0
- data/vendor/assets/javascripts/.keep +0 -0
- data/vendor/assets/stylesheets/.keep +0 -0
- metadata +407 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'rubygems'
|
3
|
+
require 'spork'
|
4
|
+
# uncomment the following line to use spork with the debugger
|
5
|
+
# require 'spork/ext/ruby-debug'
|
6
|
+
|
7
|
+
Spork.prefork do
|
8
|
+
# Loading more in this block will cause your tests to run faster. However,
|
9
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
10
|
+
# need to restart spork for it take effect.
|
11
|
+
|
12
|
+
ENV['RAILS_ENV'] ||= 'test'
|
13
|
+
require File.expand_path('../../config/environment', __FILE__)
|
14
|
+
require 'rspec/rails'
|
15
|
+
require 'rspec/autorun'
|
16
|
+
require 'capybara/dsl'
|
17
|
+
require 'capybara/rspec'
|
18
|
+
require 'capybara/poltergeist'
|
19
|
+
require 'turnip'
|
20
|
+
require 'turnip/capybara'
|
21
|
+
require 'simplecov' if ENV['COVERAGE'] || ENV['COVERALLS']
|
22
|
+
|
23
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
24
|
+
# in spec/support/ and its subdirectories.
|
25
|
+
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
26
|
+
|
27
|
+
# Checks for pending migrations before tests are run.
|
28
|
+
# If you are not using ActiveRecord, you can remove this line.
|
29
|
+
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
# ## Mock Framework
|
33
|
+
#
|
34
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the
|
35
|
+
# appropriate line:
|
36
|
+
#
|
37
|
+
# config.mock_with :mocha
|
38
|
+
# config.mock_with :flexmock
|
39
|
+
# config.mock_with :rr
|
40
|
+
|
41
|
+
# Remove this line if you're not using ActiveRecord or
|
42
|
+
# ActiveRecord fixtures
|
43
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
44
|
+
|
45
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
46
|
+
# examples within a transaction, remove the following line or assign false
|
47
|
+
# instead of true.
|
48
|
+
config.use_transactional_fixtures = false
|
49
|
+
|
50
|
+
# If true, the base class of anonymous controllers will be inferred
|
51
|
+
# automatically. This will be the default behavior in future versions of
|
52
|
+
# rspec-rails.
|
53
|
+
config.infer_base_class_for_anonymous_controllers = false
|
54
|
+
|
55
|
+
# Run specs in random order to surface order dependencies. If you find an
|
56
|
+
# order dependency and want to debug it, you can fix the order by providing
|
57
|
+
# the seed, which is printed after each run.
|
58
|
+
# --seed 1234
|
59
|
+
config.order = 'random'
|
60
|
+
|
61
|
+
twb = (ENV['TARGET_WEB_BROWZER'] || ENV['TWB']).try(:downcase)
|
62
|
+
case twb
|
63
|
+
when 'firefox', 'ie', 'chrome'
|
64
|
+
Capybara.register_driver :selenium do |app|
|
65
|
+
opts = { browser: twb.to_sym }
|
66
|
+
|
67
|
+
dir = downloads_dir.to_s
|
68
|
+
dir.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if windows?
|
69
|
+
case twb
|
70
|
+
when 'firefox'
|
71
|
+
opts[:profile] = profile = Selenium::WebDriver::Firefox::Profile.new
|
72
|
+
profile['browser.download.folderList'] = 2 # custom location
|
73
|
+
profile['browser.download.dir'] = dir
|
74
|
+
profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/plain'
|
75
|
+
when 'ie'
|
76
|
+
opts[:introduce_flakiness_by_ignoring_security_domains] = true
|
77
|
+
when 'chrome'
|
78
|
+
FileUtils.mkdir_p(dir)
|
79
|
+
opts[:prefs] = {
|
80
|
+
download: {
|
81
|
+
prompt_for_download: false,
|
82
|
+
default_directory: dir,
|
83
|
+
directory_upgrade: true,
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
opts[:switches] =
|
88
|
+
%w(
|
89
|
+
--ignore-certificate-errors
|
90
|
+
--disable-popup-blocking
|
91
|
+
--disable-translate
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
Capybara::Selenium::Driver.new(app, opts)
|
96
|
+
end
|
97
|
+
Capybara.javascript_driver = :selenium
|
98
|
+
else
|
99
|
+
Capybara.javascript_driver = :poltergeist
|
100
|
+
end
|
101
|
+
|
102
|
+
config.include JsonSpec::Helpers
|
103
|
+
|
104
|
+
config.after(javascript: true) do
|
105
|
+
page.execute_script('window.onbeforeunload = null')
|
106
|
+
FileUtils.rm_rf(downloads_dir) if selenium?
|
107
|
+
end
|
108
|
+
|
109
|
+
config.before(:all, javascript: true, standalone: true) do
|
110
|
+
expire_assets_cache
|
111
|
+
end
|
112
|
+
|
113
|
+
config.after(:all, javascript: true, standalone: true) do
|
114
|
+
expire_assets_cache
|
115
|
+
end
|
116
|
+
|
117
|
+
config.before(javascript: true, standalone: true) do
|
118
|
+
page.driver.restart
|
119
|
+
|
120
|
+
@_rails_env = Rails.env
|
121
|
+
Rails.env = ENV['RAILS_ENV'] = 'standalone'
|
122
|
+
@_home = ENV['HOME']
|
123
|
+
@_tmpdir = ENV['HOME'] = Dir.mktmpdir('smalruby-')
|
124
|
+
end
|
125
|
+
|
126
|
+
config.after(javascript: true, standalone: true) do
|
127
|
+
FileUtils.remove_entry_secure(@_tmpdir)
|
128
|
+
ENV['HOME'] = @_home
|
129
|
+
Rails.env = ENV['RAILS_ENV'] = @_rails_env
|
130
|
+
|
131
|
+
page.driver.restart
|
132
|
+
end
|
133
|
+
|
134
|
+
config.before :suite do
|
135
|
+
DatabaseRewinder.clean_all
|
136
|
+
end
|
137
|
+
|
138
|
+
config.after :each do
|
139
|
+
DatabaseRewinder.clean
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
Spork.each_run do
|
145
|
+
# This code will be run each time you run your specs.
|
146
|
+
|
147
|
+
# http://penguinlab.jp/blog/post/2256# より
|
148
|
+
if Spork.using_spork?
|
149
|
+
# app 下のファイル / locale / routes をリロード
|
150
|
+
# railties-3.2.3/lib/rails/application/finisher.rb あたりを参考に
|
151
|
+
Rails.application.reloaders.each { |reloader| reloader.execute_if_updated }
|
152
|
+
|
153
|
+
# machinist gem を利用してる場合、blueprints を再度読み直す
|
154
|
+
# load "#{File.dirname(__FILE__)}/support/blueprints.rb"
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
text_editor = 'テキストエディタ'
|
4
|
+
|
5
|
+
step 'テキストエディタにフォーカスがあること' do
|
6
|
+
expect(page.evaluate_script(<<-JS)).to be_true
|
7
|
+
ace.edit('#{NAME_INFO[text_editor][:id]}').isFocused()
|
8
|
+
JS
|
9
|
+
end
|
10
|
+
|
11
|
+
step 'テキストエディタの :row 行目の :column 文字目にカーソルがあること' do |row, column|
|
12
|
+
get_cursor_position_js =
|
13
|
+
"ace.edit('#{NAME_INFO[text_editor][:id]}').getCursorPosition()"
|
14
|
+
expect(page.evaluate_script("#{get_cursor_position_js}.row")).to eq(row.to_i)
|
15
|
+
expect(page.evaluate_script("#{get_cursor_position_js}.column"))
|
16
|
+
.to eq(column.to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
step 'テキストエディタに :program を入力済みである' do |program|
|
20
|
+
send 'テキストエディタにプログラムを入力済みである:', program
|
21
|
+
end
|
22
|
+
|
23
|
+
step 'テキストエディタにプログラムを入力済みである:' do |program|
|
24
|
+
page.execute_script(<<-JS)
|
25
|
+
ace.edit('#{NAME_INFO[text_editor][:id]}')
|
26
|
+
.getSession()
|
27
|
+
.getDocument()
|
28
|
+
.setValue('#{program.gsub(/'/, "\\\\'")}')
|
29
|
+
JS
|
30
|
+
end
|
31
|
+
|
32
|
+
step 'テキストエディタに :filename を読み込むこと' do |filename|
|
33
|
+
js = <<-JS
|
34
|
+
ace.edit('#{NAME_INFO[text_editor][:id]}')
|
35
|
+
.getSession()
|
36
|
+
.getDocument()
|
37
|
+
.getValue()
|
38
|
+
JS
|
39
|
+
path = Pathname(fixture_path).join(filename)
|
40
|
+
expect(page.evaluate_script(js)).to eq(path.read)
|
41
|
+
end
|
42
|
+
|
43
|
+
step 'テキストエディタのプログラムは以下であること:' do |program|
|
44
|
+
expect(page.evaluate_script(<<-JS)).to eq(program)
|
45
|
+
ace.edit('#{NAME_INFO[text_editor][:id]}')
|
46
|
+
.getSession()
|
47
|
+
.getDocument()
|
48
|
+
.getValue()
|
49
|
+
JS
|
50
|
+
end
|
51
|
+
|
52
|
+
step 'テキストエディタのプログラムは :program であること' do |program|
|
53
|
+
expect(page.evaluate_script(<<-JS)).to eq(program)
|
54
|
+
ace.edit('#{NAME_INFO[text_editor][:id]}')
|
55
|
+
.getSession()
|
56
|
+
.getDocument()
|
57
|
+
.getValue()
|
58
|
+
JS
|
59
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
::NAME_INFO = {
|
4
|
+
'トップページ' => {
|
5
|
+
path: '/',
|
6
|
+
},
|
7
|
+
'エディタ' => {
|
8
|
+
path: '/',
|
9
|
+
},
|
10
|
+
|
11
|
+
'Rubyタブ' => {
|
12
|
+
id: 'ruby-tab',
|
13
|
+
selector: '#ruby-tab',
|
14
|
+
},
|
15
|
+
'テキストエディタ' => {
|
16
|
+
id: 'text-editor',
|
17
|
+
selector: '#text-editor',
|
18
|
+
},
|
19
|
+
'プログラム名の入力欄' => {
|
20
|
+
id: 'filename',
|
21
|
+
selector: '#filename',
|
22
|
+
},
|
23
|
+
'チェックボタン' => {
|
24
|
+
id: 'check-button',
|
25
|
+
selector: '#check-button',
|
26
|
+
},
|
27
|
+
'セーブボタン' => {
|
28
|
+
id: 'save-button',
|
29
|
+
selector: '#save-button',
|
30
|
+
},
|
31
|
+
'ロードボタン' => {
|
32
|
+
id: 'load-button',
|
33
|
+
selector: '#load-button',
|
34
|
+
},
|
35
|
+
'メッセージ' => {
|
36
|
+
id: 'messages',
|
37
|
+
selector: '#messages',
|
38
|
+
},
|
39
|
+
}
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
step ':name にアクセスする' do |name|
|
4
|
+
visit NAME_INFO[name][:path]
|
5
|
+
|
6
|
+
if poltergeist?
|
7
|
+
page.execute_script(<<-JS)
|
8
|
+
if (window.confirmMsg == undefined) {
|
9
|
+
window.confirmMsg = null;
|
10
|
+
window.confirm = function(msg) {
|
11
|
+
window.confirmMsg = msg;
|
12
|
+
return true;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
JS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
step ':name が表示されていること' do |name|
|
20
|
+
expect(page).to have_selector(NAME_INFO[name][:selector])
|
21
|
+
end
|
22
|
+
|
23
|
+
step ':name 画面を表示する' do |name|
|
24
|
+
send ':name にアクセスする', name
|
25
|
+
end
|
26
|
+
|
27
|
+
step 'プログラムの名前に :filename を指定する' do |filename|
|
28
|
+
fill_in('filename', with: filename)
|
29
|
+
end
|
30
|
+
|
31
|
+
step ':name をクリックする' do |name|
|
32
|
+
click_on(NAME_INFO[name][:id])
|
33
|
+
end
|
34
|
+
|
35
|
+
step 'ダウンロードが完了するまで待つ' do
|
36
|
+
start_time = Time.now
|
37
|
+
if poltergeist?
|
38
|
+
until page.response_headers['Content-Disposition'] ||
|
39
|
+
(start_time + 5.seconds) < Time.now
|
40
|
+
sleep(1)
|
41
|
+
end
|
42
|
+
elsif selenium?
|
43
|
+
sleep(1) until downloads_dir.exist? || (start_time + 5.seconds) < Time.now
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
step ':filename をダウンロードすること' do |filename|
|
48
|
+
step 'ダウンロードが完了するまで待つ'
|
49
|
+
if poltergeist?
|
50
|
+
expect(page.response_headers['Content-Disposition'])
|
51
|
+
.to eq("attachment; filename=\"#{filename}\"")
|
52
|
+
expect(page.response_headers['Content-Type'])
|
53
|
+
.to eq('text/plain; charset=utf-8')
|
54
|
+
elsif selenium?
|
55
|
+
expect(downloads_dir.join(filename)).to be_exist
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
step 'ダウンロードしないこと' do
|
60
|
+
if poltergeist?
|
61
|
+
expect(page.response_headers['Content-Disposition']).to be_nil
|
62
|
+
elsif selenium?
|
63
|
+
expect(downloads_dir).not_to be_exist
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
step ':name にフォーカスを移す' do |name|
|
68
|
+
page.execute_script(<<-JS)
|
69
|
+
$('#{NAME_INFO[name][:selector]}').focus()
|
70
|
+
JS
|
71
|
+
end
|
72
|
+
|
73
|
+
step ':name にフォーカスがあること' do |name|
|
74
|
+
# HACK: 現在のPhantomJSでは$(':focus')は動作しない
|
75
|
+
# https://github.com/netzpirat/guard-jasmine/issues/48
|
76
|
+
expect(page.evaluate_script(<<-JS)).to be_true
|
77
|
+
$('#{NAME_INFO[name][:selector]}').get(0) == document.activeElement
|
78
|
+
JS
|
79
|
+
end
|
80
|
+
|
81
|
+
step ':filename をロードする' do |filename|
|
82
|
+
step '"ロードボタン" にフォーカスを移す'
|
83
|
+
|
84
|
+
# HACK: input#load-file[type="file"]は非表示要素であるため、.show()し
|
85
|
+
# ないと見つけられずattach_fileが失敗する
|
86
|
+
page.execute_script("$('#load-file').show()")
|
87
|
+
|
88
|
+
path = Pathname(fixture_path).join(filename).to_s
|
89
|
+
path.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if windows?
|
90
|
+
attach_file('load-file', path)
|
91
|
+
end
|
92
|
+
|
93
|
+
step 'JavaScriptによるリクエストが終わるまで待つ' do
|
94
|
+
start_time = Time.now
|
95
|
+
until page.evaluate_script('jQuery.isReady && jQuery.active == 0') ||
|
96
|
+
(start_time + 5.seconds) < Time.now
|
97
|
+
sleep 1
|
98
|
+
end
|
99
|
+
end
|
100
|
+
step ':name は :value であること' do |name, value|
|
101
|
+
expect(page.evaluate_script(<<-JS)).to eq(value)
|
102
|
+
$('#{NAME_INFO[name][:selector]}').val()
|
103
|
+
JS
|
104
|
+
end
|
105
|
+
|
106
|
+
step ':name に :message を含むこと' do |name, message|
|
107
|
+
expect(page.find(NAME_INFO[name][:selector])).to have_content(message)
|
108
|
+
end
|
109
|
+
|
110
|
+
step ':name に :message を含まないこと' do |name, message|
|
111
|
+
expect(page.find(NAME_INFO[name][:selector])).to have_no_content(message)
|
112
|
+
end
|
113
|
+
|
114
|
+
step 'ページをリロードする' do
|
115
|
+
begin
|
116
|
+
step '"エディタ" 画面を表示する'
|
117
|
+
rescue Capybara::Poltergeist::TimeoutError => e
|
118
|
+
Rails.logger.debug("#{e.class.name}: #{e.message}")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
step '警告ダイアログの :name ボタンをクリックする' do |name|
|
123
|
+
case name
|
124
|
+
when 'dismiss'
|
125
|
+
page.driver.browser.switch_to.alert.dismiss if selenium?
|
126
|
+
else
|
127
|
+
page.driver.browser.switch_to.alert.accept if selenium?
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
step '確認メッセージ :message を表示すること' do |message|
|
132
|
+
message.gsub!('\n', "\n")
|
133
|
+
if poltergeist?
|
134
|
+
actual = page.evaluate_script('window.confirmMsg')
|
135
|
+
page.execute_script('window.confirmMsg = null')
|
136
|
+
expect(actual).to eq(message)
|
137
|
+
elsif selenium?
|
138
|
+
expect(page.driver.browser.switch_to.alert.text).to eq(message)
|
139
|
+
page.driver.browser.switch_to.alert.dismiss
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
step '確認メッセージを表示しないこと' do
|
144
|
+
if poltergeist?
|
145
|
+
actual = page.evaluate_script('window.confirmMsg')
|
146
|
+
page.execute_script('window.confirmMsg = null')
|
147
|
+
expect(actual).to be_nil
|
148
|
+
elsif selenium?
|
149
|
+
expect {
|
150
|
+
page.driver.browser.switch_to.alert
|
151
|
+
}.to raise_exception(Selenium::WebDriver::Error::NoAlertPresentError)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
step '実際にはファイルをロードしないようにしておく' do
|
156
|
+
if selenium?
|
157
|
+
page.execute_script("$('#load-button').off('click')")
|
158
|
+
page.execute_script(<<-JS)
|
159
|
+
$('#load-button').click(function(e) {
|
160
|
+
e.preventDefault();
|
161
|
+
if (changed) {
|
162
|
+
confirm('まだセーブしていないのでロードするとプログラムが消えてしまうよ!それでもロードしますか?');
|
163
|
+
}
|
164
|
+
})
|
165
|
+
JS
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
step 'ホームディレクトリに :program という内容の :filename が存在する' do |program, filename|
|
170
|
+
File.open(Pathname("~/#{filename}").expand_path, 'w') do |f|
|
171
|
+
f.write(program)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
step 'ホームディレクトリに :filename が存在すること' do |filename|
|
176
|
+
path = Pathname("~/#{filename}").expand_path
|
177
|
+
expect(path).to be_exist
|
178
|
+
end
|
179
|
+
|
180
|
+
step 'ホームディレクトリの :filename の内容が :program であること' do |filename, program|
|
181
|
+
path = Pathname("~/#{filename}").expand_path
|
182
|
+
expect(path.read).to eq(program)
|
183
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# assetsのキャッシュを削除する
|
4
|
+
#
|
5
|
+
# ただし、このメソッドを呼び出した後で page.driver.restart を実行しなけ
|
6
|
+
# ればブラウザ側のキャッシュが有効になったままとなる。
|
7
|
+
def expire_assets_cache
|
8
|
+
env = Rails.application.assets
|
9
|
+
if Rails.application.config.cache_classes
|
10
|
+
env.instance_variable_set('@assets', {})
|
11
|
+
env.instance_variable_set('@digests', {})
|
12
|
+
env = env.instance_variable_get('@environment')
|
13
|
+
end
|
14
|
+
env.send(:expire_index!)
|
15
|
+
Dir.glob(Rails.root.join('tmp/cache/assets/test/sprockets/*')) { |f|
|
16
|
+
FileUtils.remove_entry_secure(f)
|
17
|
+
}
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
def poltergeist?
|
4
|
+
/\Apoltergeist/ =~ Capybara.javascript_driver.to_s
|
5
|
+
end
|
6
|
+
|
7
|
+
def selenium?
|
8
|
+
/\Aselenium/ =~ Capybara.javascript_driver.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def windows?
|
12
|
+
/windows|mingw|cygwin/i =~ RbConfig::CONFIG['arch']
|
13
|
+
end
|
14
|
+
|
15
|
+
def downloads_dir
|
16
|
+
Pathname(Rails.root).join('tmp/downloads')
|
17
|
+
end
|
data/spec/support/env.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
# Rails.envをstandaloneにする
|
6
|
+
shared_context 'set standalone rails env', set_standalone_rails_env: true do
|
7
|
+
before do
|
8
|
+
@_rails_env = Rails.env
|
9
|
+
Rails.env = ENV['RAILS_ENV'] = 'standalone'
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
Rails.env = ENV['RAILS_ENV'] = @_rails_env
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
File without changes
|