smalruby-editor 0.0.1
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 +24 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.simplecov +7 -0
- data/.travis.yml +23 -0
- data/Gemfile +77 -0
- data/Gemfile.lock +258 -0
- data/LICENSE +22 -0
- data/Procfile +1 -0
- data/README.rdoc +45 -0
- data/Rakefile +6 -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 +52 -0
- data/app/assets/stylesheets/application.css +20 -0
- data/app/assets/stylesheets/editor.css.scss +13 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/concerns/.keep +0 -0
- data/app/controllers/editor_controller.rb +22 -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/views/editor/index.html.erb +16 -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 +86 -0
- data/config.ru +4 -0
- data/config/application.rb +28 -0
- data/config/boot.rb +4 -0
- data/config/database.yml.mysql2 +39 -0
- data/config/database.yml.sqlite3 +25 -0
- data/config/database.yml.travis +5 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +29 -0
- data/config/environments/production.rb +80 -0
- data/config/environments/standalone.rb +15 -0
- data/config/environments/test.rb +36 -0
- data/config/initializers/backtrace_silencers.rb +7 -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 +12 -0
- data/config/initializers/session_store.rb +3 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +63 -0
- data/config/unicorn.rb +22 -0
- data/db/schema.rb +16 -0
- data/db/seeds.rb +7 -0
- data/lib/assets/.keep +0 -0
- data/lib/smalruby_editor.rb +4 -0
- data/lib/smalruby_editor/version.rb +3 -0
- data/lib/tasks/.keep +0 -0
- data/lib/tasks/gem.rake +5 -0
- data/lib/tasks/rspec.rake +16 -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/favicon.ico +0 -0
- data/public/robots.txt +5 -0
- data/smalruby-editor.gemspec +50 -0
- data/spec/acceptance/editor.feature +58 -0
- data/spec/controllers/editor_controller_spec.rb +52 -0
- data/spec/fixtures/files/01.rb +57 -0
- data/spec/helpers/editor_helper_spec.rb +14 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/steps/editor_steps.rb +106 -0
- data/vendor/assets/javascripts/.keep +0 -0
- data/vendor/assets/stylesheets/.keep +0 -0
- metadata +367 -0
data/public/422.html
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/422.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
+
</div>
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
57
|
+
</body>
|
58
|
+
</html>
|
data/public/500.html
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style>
|
6
|
+
body {
|
7
|
+
background-color: #EFEFEF;
|
8
|
+
color: #2E2F30;
|
9
|
+
text-align: center;
|
10
|
+
font-family: arial, sans-serif;
|
11
|
+
}
|
12
|
+
|
13
|
+
div.dialog {
|
14
|
+
width: 25em;
|
15
|
+
margin: 4em auto 0 auto;
|
16
|
+
border: 1px solid #CCC;
|
17
|
+
border-right-color: #999;
|
18
|
+
border-left-color: #999;
|
19
|
+
border-bottom-color: #BBB;
|
20
|
+
border-top: #B00100 solid 4px;
|
21
|
+
border-top-left-radius: 9px;
|
22
|
+
border-top-right-radius: 9px;
|
23
|
+
background-color: white;
|
24
|
+
padding: 7px 4em 0 4em;
|
25
|
+
}
|
26
|
+
|
27
|
+
h1 {
|
28
|
+
font-size: 100%;
|
29
|
+
color: #730E15;
|
30
|
+
line-height: 1.5em;
|
31
|
+
}
|
32
|
+
|
33
|
+
body > p {
|
34
|
+
width: 33em;
|
35
|
+
margin: 0 auto 1em;
|
36
|
+
padding: 1em 0;
|
37
|
+
background-color: #F7F7F7;
|
38
|
+
border: 1px solid #CCC;
|
39
|
+
border-right-color: #999;
|
40
|
+
border-bottom-color: #999;
|
41
|
+
border-bottom-left-radius: 4px;
|
42
|
+
border-bottom-right-radius: 4px;
|
43
|
+
border-top-color: #DADADA;
|
44
|
+
color: #666;
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
+
}
|
47
|
+
</style>
|
48
|
+
</head>
|
49
|
+
|
50
|
+
<body>
|
51
|
+
<!-- This file lives in public/500.html -->
|
52
|
+
<div class="dialog">
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
54
|
+
</div>
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
56
|
+
</body>
|
57
|
+
</html>
|
data/public/favicon.ico
ADDED
File without changes
|
data/public/robots.txt
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'smalruby_editor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'smalruby-editor'
|
8
|
+
spec.version = SmalrubyEditor::VERSION
|
9
|
+
|
10
|
+
spec.authors = ['Kouji Takao']
|
11
|
+
spec.email = ['kouji.takao@gmail.com']
|
12
|
+
spec.description = %q{The smalruby-editor is a visual programming editor that can create a Ruby script by combining individual blocks similar to Scratch. It can also enter the program as better than Scratch.}
|
13
|
+
spec.summary = %q{A visual programming editor.}
|
14
|
+
spec.homepage = 'https://github.com/smalruby/smalruby-editor'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = []
|
18
|
+
if File.exist?(File.expand_path('../.git', __FILE__))
|
19
|
+
spec.files += `git ls-files`.split($/)
|
20
|
+
end
|
21
|
+
spec.files += Dir.glob('public/assets/**/*')
|
22
|
+
spec.default_executable = 'smalruby-editor'
|
23
|
+
spec.executables = ['smalruby-editor']
|
24
|
+
spec.extra_rdoc_files = ["README.rdoc", "LICENSE"]
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
spec.rdoc_options = ["--title", "Smalruby Editor -- A visual programming editor", "--line-numbers", "--main", "README", "--exclude", "app", "--exclude", "bin", "--exclude", "config", "--exclude", "db", "--exclude", "features", "--exclude", "lib", "--exclude", "log", "--exclude", "pkg", "--exclude", "public", "--exclude", "script", "--exclude", "spec", "--exclude", "test", "--exclude", "tmp", "--exclude", "vendor"]
|
28
|
+
|
29
|
+
runtime_dependencies =
|
30
|
+
[
|
31
|
+
['rails', '4.0.1'],
|
32
|
+
['sqlite3'],
|
33
|
+
['sass-rails', '~> 4.0.0'],
|
34
|
+
['uglifier', '>= 1.3.0'],
|
35
|
+
['coffee-rails', '~> 4.0.0'],
|
36
|
+
['jquery-rails'],
|
37
|
+
['turbolinks'],
|
38
|
+
['jbuilder', '~> 1.2'],
|
39
|
+
['ace-rails-ap'],
|
40
|
+
['flatstrap-sass'],
|
41
|
+
['font-awesome-rails'],
|
42
|
+
['jquery-fileupload-rails'],
|
43
|
+
]
|
44
|
+
runtime_dependencies.each do |args|
|
45
|
+
spec.add_runtime_dependency *args
|
46
|
+
end
|
47
|
+
|
48
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
49
|
+
spec.add_development_dependency 'rake'
|
50
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# language: ja
|
3
|
+
@javascript
|
4
|
+
機能: Rubyのプログラムをテキストエディタ機能で編集できる
|
5
|
+
シナリオ: トップページにアクセスしてエディタ画面を表示する
|
6
|
+
もし "トップページ" にアクセスする
|
7
|
+
|
8
|
+
ならば "Rubyタブ" が表示されていること
|
9
|
+
かつ "テキストエディタ" が表示されていること
|
10
|
+
かつ "プログラム名の入力欄" が表示されていること
|
11
|
+
かつ "セーブボタン" が表示されていること
|
12
|
+
|
13
|
+
シナリオ: セーブボタンを押してプログラムを保存できる
|
14
|
+
前提 "エディタ" 画面を表示する
|
15
|
+
かつ "テキストエディタ" にプログラムを入力済みである:
|
16
|
+
"""
|
17
|
+
puts "Hello, World!"
|
18
|
+
"""
|
19
|
+
|
20
|
+
もし プログラムの名前に "01.rb" を指定する
|
21
|
+
かつ "セーブボタン" をクリックする
|
22
|
+
かつ JavaScriptによるリクエストが終わるまで待つ
|
23
|
+
|
24
|
+
ならば "01.rb" をダウンロードする
|
25
|
+
かつ ダウンロードしたファイルの内容が正しい:
|
26
|
+
"""
|
27
|
+
puts "Hello, World!"
|
28
|
+
"""
|
29
|
+
|
30
|
+
シナリオ: ファイル名を入力せずにセーブボタンを押す
|
31
|
+
前提 "エディタ" 画面を表示する
|
32
|
+
|
33
|
+
もし "セーブボタン" をクリックする
|
34
|
+
|
35
|
+
ならば ダウンロードしない
|
36
|
+
かつ "プログラム名の入力欄" にフォーカスが移る
|
37
|
+
|
38
|
+
シナリオ: ロードボタンを押してプログラムを読み込む
|
39
|
+
前提 "エディタ" 画面を表示する
|
40
|
+
|
41
|
+
もし "files/01.rb" をアップロードする
|
42
|
+
かつ JavaScriptによるリクエストが終わるまで待つ
|
43
|
+
|
44
|
+
ならば "テキストエディタ" に "files/01.rb" を読み込む
|
45
|
+
かつ "プログラム名の入力欄" に "01.rb" が入力される
|
46
|
+
|
47
|
+
シナリオ: プログラムを入力済み状態でプログラムを読み込む
|
48
|
+
前提 "エディタ" 画面を表示する
|
49
|
+
かつ "テキストエディタ" にプログラムを入力済みである:
|
50
|
+
"""
|
51
|
+
puts "Hello, World!"
|
52
|
+
"""
|
53
|
+
|
54
|
+
もし "files/01.rb" をアップロードする
|
55
|
+
かつ JavaScriptによるリクエストが終わるまで待つ
|
56
|
+
|
57
|
+
ならば "テキストエディタ" に "files/01.rb" を読み込む
|
58
|
+
かつ "プログラム名の入力欄" に "01.rb" が入力される
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'nkf'
|
4
|
+
|
5
|
+
describe EditorController do
|
6
|
+
describe "エディタ画面を表示する (GET 'index')" do
|
7
|
+
it 'returns http success' do
|
8
|
+
get 'index'
|
9
|
+
response.should be_success
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "プログラムを保存する (GET 'save_file')" do
|
14
|
+
it 'アップロードされたプログラムをダウンロードできる' do
|
15
|
+
params = {
|
16
|
+
filename: '01.rb',
|
17
|
+
source: 'puts "Hello, World!"',
|
18
|
+
}.with_indifferent_access
|
19
|
+
|
20
|
+
expect(@controller).to receive(:send_data)
|
21
|
+
.with(params[:source], filename: params[:filename],
|
22
|
+
disposition: 'attachment',
|
23
|
+
type: 'text/plain; charset=utf-8')
|
24
|
+
.once.and_call_original
|
25
|
+
|
26
|
+
get 'save_file', params
|
27
|
+
|
28
|
+
expect(response).to be_success
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "プログラムを読み込む (POST 'load_file')" do
|
33
|
+
let(:load_file) { fixture_file_upload('files/01.rb') }
|
34
|
+
|
35
|
+
before do
|
36
|
+
post 'load_file', load_file: load_file
|
37
|
+
end
|
38
|
+
|
39
|
+
it { expect(response).to be_success }
|
40
|
+
|
41
|
+
it 'アップロードされたプログラムの情報をJSON形式でダウンロードできる' do
|
42
|
+
load_file.rewind
|
43
|
+
file = {
|
44
|
+
name: load_file.original_filename,
|
45
|
+
type: load_file.content_type,
|
46
|
+
size: load_file.size,
|
47
|
+
source: NKF.nkf('-w', load_file.read),
|
48
|
+
}
|
49
|
+
expect(response.body).to be_json_eql(file.to_json)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# 画面をクリックして隠れている車を1台探してみよう
|
3
|
+
|
4
|
+
require "smalruby"
|
5
|
+
|
6
|
+
# <プログラム> # <説明>
|
7
|
+
canvas1 = Canvas.new # 背景を用意する
|
8
|
+
car1 = Character.new(x: 0, y: 148, costume: "car3.png", visible: true)
|
9
|
+
# 車を用意する (最初に隠しておく)
|
10
|
+
|
11
|
+
# <プログラム> # <説明>
|
12
|
+
canvas1.on(:start) do # (背景は) 始まったとき
|
13
|
+
draw_font(x: 0, y: 0,
|
14
|
+
string: "画面をクリックして隠れている車を探してね",
|
15
|
+
size: 32) # (0, 0) に (32) の大きさで
|
16
|
+
# 「画面をクリックして隠れている車を探してね」の
|
17
|
+
# 文章を表示する
|
18
|
+
draw_font(x: 0, y: 32,
|
19
|
+
string: "ヒント:線の少し上だよ",
|
20
|
+
size: 24) # (0, 32) に (24) の大きさで
|
21
|
+
# 「ヒント:線の少し上だよ」の
|
22
|
+
# 文章を表示する
|
23
|
+
box_fill(x1: 0, y1: 200,
|
24
|
+
x2: 639, y2: 204,
|
25
|
+
color: "red") # (0, 200)-(639, 204) の四角を
|
26
|
+
# (white) 色で塗りつぶす
|
27
|
+
end
|
28
|
+
|
29
|
+
# <プログラム> # <説明>
|
30
|
+
canvas1.on(:click) do |x, y| # (背景は) クリックしたとき
|
31
|
+
canvas2 = Canvas.new(x: x - 9, y: y - 9, width: 20, height: 20)
|
32
|
+
# (お絵かき) を用意する
|
33
|
+
canvas2.on(:start) do # >> (お絵かきは) 始まったとき
|
34
|
+
circle_fill(x: 9, y: 9, r: 9, color: "white")
|
35
|
+
# >> (9, 9)、半径9の円をwhite色で塗りつぶす
|
36
|
+
sleep(0.5) # >> (0.5) 秒待つ
|
37
|
+
vanish # >> (お絵かきを) 取り除く
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# <プログラム> # <説明>
|
42
|
+
car1.on(:start) do # (車は) プログラムが始まったとき
|
43
|
+
speed = rand(10..20) # (speed) を (5~10までのランダム) にする
|
44
|
+
loop do # ずっと
|
45
|
+
move(speed) # >> (speed) 歩動かす
|
46
|
+
turn_if_reach_wall # >> もし端に着いたら、跳ね返る
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# <プログラム> # <説明>
|
51
|
+
car1.on(:click) do # (車は) クリックしたとき
|
52
|
+
if self.visible == false # もし (隠している) だったら
|
53
|
+
self.visible = true # >> 表示する
|
54
|
+
else # そうでなければ
|
55
|
+
self.visible = false # >> 隠す
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the EditorHelper. For example:
|
5
|
+
#
|
6
|
+
# describe EditorHelper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# expect(helper.concat_strings("this","that")).to eq("this that")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
describe EditorHelper do
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
4
|
+
require 'rspec/rails'
|
5
|
+
require 'rspec/autorun'
|
6
|
+
require 'capybara/dsl'
|
7
|
+
require 'capybara/rspec'
|
8
|
+
require 'capybara/poltergeist'
|
9
|
+
require 'turnip'
|
10
|
+
require 'turnip/capybara'
|
11
|
+
require 'simplecov' if ENV['COVERAGE'] || ENV['COVERALLS']
|
12
|
+
|
13
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
14
|
+
# in spec/support/ and its subdirectories.
|
15
|
+
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
16
|
+
|
17
|
+
Dir.glob("spec/steps/**/*_steps.rb") { |f| load f, true }
|
18
|
+
|
19
|
+
# Checks for pending migrations before tests are run.
|
20
|
+
# If you are not using ActiveRecord, you can remove this line.
|
21
|
+
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
22
|
+
|
23
|
+
RSpec.configure do |config|
|
24
|
+
# ## Mock Framework
|
25
|
+
#
|
26
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
27
|
+
#
|
28
|
+
# config.mock_with :mocha
|
29
|
+
# config.mock_with :flexmock
|
30
|
+
# config.mock_with :rr
|
31
|
+
|
32
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
33
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
34
|
+
|
35
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
36
|
+
# examples within a transaction, remove the following line or assign false
|
37
|
+
# instead of true.
|
38
|
+
config.use_transactional_fixtures = true
|
39
|
+
|
40
|
+
# If true, the base class of anonymous controllers will be inferred
|
41
|
+
# automatically. This will be the default behavior in future versions of
|
42
|
+
# rspec-rails.
|
43
|
+
config.infer_base_class_for_anonymous_controllers = false
|
44
|
+
|
45
|
+
# Run specs in random order to surface order dependencies. If you find an
|
46
|
+
# order dependency and want to debug it, you can fix the order by providing
|
47
|
+
# the seed, which is printed after each run.
|
48
|
+
# --seed 1234
|
49
|
+
config.order = "random"
|
50
|
+
|
51
|
+
|
52
|
+
case (ENV['TARGET_WEB_BROWZER'] || ENV['TWB']).try(:downcase)
|
53
|
+
when 'firefox'
|
54
|
+
Capybara.javascript_driver = :selenium
|
55
|
+
when 'ie'
|
56
|
+
Capybara.register_driver :selenium_ie do |app|
|
57
|
+
Capybara::Selenium::Driver.new(app, browser: :ie, introduce_flakiness_by_ignoring_security_domains: true)
|
58
|
+
end
|
59
|
+
Capybara.javascript_driver = :selenium_ie
|
60
|
+
when 'chrome'
|
61
|
+
Capybara.register_driver :selenium_chrome do |app|
|
62
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
63
|
+
end
|
64
|
+
Capybara.javascript_driver = :selenium_chrome
|
65
|
+
else
|
66
|
+
Capybara.javascript_driver = :poltergeist
|
67
|
+
end
|
68
|
+
|
69
|
+
config.include JsonSpec::Helpers
|
70
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: 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: 'save-button',
|
25
|
+
selector: '#save-button',
|
26
|
+
},
|
27
|
+
}
|
28
|
+
|
29
|
+
step ':name にアクセスする' do |name|
|
30
|
+
visit name_info[name][:path]
|
31
|
+
end
|
32
|
+
|
33
|
+
step ':name が表示されていること' do |name|
|
34
|
+
expect(page).to have_selector(name_info[name][:selector])
|
35
|
+
end
|
36
|
+
|
37
|
+
step ':name 画面を表示する' do |name|
|
38
|
+
visit name_info[name][:path]
|
39
|
+
end
|
40
|
+
|
41
|
+
step ':text_editor にプログラムを入力済みである:' do |text_editor, source|
|
42
|
+
page.execute_script(<<-JS)
|
43
|
+
ace.edit('#{name_info[text_editor][:id]}')
|
44
|
+
.getSession()
|
45
|
+
.getDocument()
|
46
|
+
.setValue('#{source}')
|
47
|
+
JS
|
48
|
+
end
|
49
|
+
|
50
|
+
step 'プログラムの名前に :filename を指定する' do |filename|
|
51
|
+
fill_in('filename', with: filename)
|
52
|
+
end
|
53
|
+
|
54
|
+
step ':name をクリックする' do |name|
|
55
|
+
click_button(name_info[name][:id])
|
56
|
+
end
|
57
|
+
|
58
|
+
step ':filename をダウンロードする' do |filename|
|
59
|
+
expect(page.response_headers['Content-Disposition'])
|
60
|
+
.to eq("attachment; filename=\"#{filename}\"")
|
61
|
+
expect(page.response_headers['Content-Type'])
|
62
|
+
.to eq('text/plain; charset=utf-8')
|
63
|
+
end
|
64
|
+
|
65
|
+
step 'ダウンロードしたファイルの内容が正しい:' do |source|
|
66
|
+
# TODO
|
67
|
+
end
|
68
|
+
|
69
|
+
step 'ダウンロードしない' do
|
70
|
+
# TODO
|
71
|
+
end
|
72
|
+
|
73
|
+
step ':name にフォーカスが移る' do |name|
|
74
|
+
# 現在のPhantomJSでは$(':focus')は動作しない
|
75
|
+
# https://github.com/netzpirat/guard-jasmine/issues/48
|
76
|
+
expect(page.evaluate_script(<<-JS)).to be_true
|
77
|
+
$('#filename').get(0) == document.activeElement
|
78
|
+
JS
|
79
|
+
end
|
80
|
+
|
81
|
+
step ':filename をアップロードする' do |filename|
|
82
|
+
page.execute_script("$('#load-file').show()")
|
83
|
+
attach_file('load-file', Pathname(fixture_path).join(filename))
|
84
|
+
end
|
85
|
+
|
86
|
+
step ':text_editor に :filename を読み込む' do |text_editor, filename|
|
87
|
+
expect(page.evaluate_script(<<-JS)).to eq(Pathname(fixture_path).join(filename).read)
|
88
|
+
ace.edit('#{name_info[text_editor][:id]}')
|
89
|
+
.getSession()
|
90
|
+
.getDocument()
|
91
|
+
.getValue()
|
92
|
+
JS
|
93
|
+
end
|
94
|
+
|
95
|
+
step ':name に :value が入力される' do |name, value|
|
96
|
+
expect(page.evaluate_script(<<-JS)).to eq(value)
|
97
|
+
$('#{name_info[name][:selector]}').val()
|
98
|
+
JS
|
99
|
+
end
|
100
|
+
|
101
|
+
step 'JavaScriptによるリクエストが終わるまで待つ' do
|
102
|
+
start_time = Time.now
|
103
|
+
page.evaluate_script('jQuery.isReady&&jQuery.active==0').class.should_not eql(String) until page.evaluate_script('jQuery.isReady&&jQuery.active==0') or (start_time + 5.seconds) < Time.now do
|
104
|
+
sleep 1
|
105
|
+
end
|
106
|
+
end
|