smalruby-editor 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of smalruby-editor might be problematic. Click here for more details.
- checksums.yaml +4 -4
 - data/Gemfile +4 -0
 - data/Gemfile.lock +6 -0
 - data/app/assets/javascripts/editor.js.coffee +10 -2
 - data/app/assets/stylesheets/editor.css.scss +6 -0
 - data/app/controllers/editor_controller.rb +9 -2
 - data/app/views/editor/index.html.erb +4 -0
 - data/bin/smalruby-editor +25 -38
 - data/config/environments/standalone.rb +3 -1
 - data/lib/smalruby_editor.rb +28 -0
 - data/lib/smalruby_editor/version.rb +1 -1
 - data/smalruby-editor.gemspec +1 -0
 - data/spec/acceptance/editor.feature +12 -2
 - data/spec/controllers/editor_controller_spec.rb +34 -13
 - data/spec/fixtures/files/favicon.ico +0 -0
 - data/spec/lib/smalruby_editor_spec.rb +64 -0
 - data/spec/steps/editor_steps.rb +123 -106
 - metadata +24 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 360c42f513b37db6a8f84589dba9fd3c5c7e0d6e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 93b6d05ffa2ccf9a84e9063b2c4fabc5296ee695
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c7abc3976abf11abd20e49524f8a0505f806a7652fa387603cc73f270a2c7facf698941a56a9f87cac11fb795be6bedf9e19486f4642f56834c5840e2166a469
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 56c0bdcd66fa1dba319f9abb89bea2101a42c99f8215bc760e6a4d6e6a19f89e7e72ba1caa04043d6af0cf79121ef322595921fff41ea44a7bc01efec5c0a424
         
     | 
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -34,6 +34,10 @@ gem 'font-awesome-rails' 
     | 
|
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
            gem 'jquery-fileupload-rails', github: 'demiazz/jquery-fileupload-rails'
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
      
 37 
     | 
    
         
            +
            gem 'shared-mime-info'
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            gem 'launchy'
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
       37 
41 
     | 
    
         
             
            group :doc do
         
     | 
| 
       38 
42 
     | 
    
         
             
              # bundle exec rake doc:rails generates the API under doc/api.
         
     | 
| 
       39 
43 
     | 
    
         
             
              gem 'sdoc', require: false
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -39,6 +39,7 @@ GEM 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  multi_json (~> 1.3)
         
     | 
| 
       40 
40 
     | 
    
         
             
                  thread_safe (~> 0.1)
         
     | 
| 
       41 
41 
     | 
    
         
             
                  tzinfo (~> 0.3.37)
         
     | 
| 
      
 42 
     | 
    
         
            +
                addressable (2.3.5)
         
     | 
| 
       42 
43 
     | 
    
         
             
                arel (4.0.1)
         
     | 
| 
       43 
44 
     | 
    
         
             
                ast (1.1.0)
         
     | 
| 
       44 
45 
     | 
    
         
             
                atomic (1.1.14)
         
     | 
| 
         @@ -95,6 +96,8 @@ GEM 
     | 
|
| 
       95 
96 
     | 
    
         
             
                  multi_json (~> 1.0)
         
     | 
| 
       96 
97 
     | 
    
         
             
                  rspec (~> 2.0)
         
     | 
| 
       97 
98 
     | 
    
         
             
                kgio (2.8.1)
         
     | 
| 
      
 99 
     | 
    
         
            +
                launchy (2.4.1)
         
     | 
| 
      
 100 
     | 
    
         
            +
                  addressable (~> 2.3)
         
     | 
| 
       98 
101 
     | 
    
         
             
                mail (2.5.4)
         
     | 
| 
       99 
102 
     | 
    
         
             
                  mime-types (~> 1.16)
         
     | 
| 
       100 
103 
     | 
    
         
             
                  treetop (~> 1.4.8)
         
     | 
| 
         @@ -178,6 +181,7 @@ GEM 
     | 
|
| 
       178 
181 
     | 
    
         
             
                  multi_json (~> 1.0)
         
     | 
| 
       179 
182 
     | 
    
         
             
                  rubyzip (~> 1.0.0)
         
     | 
| 
       180 
183 
     | 
    
         
             
                  websocket (~> 1.0.4)
         
     | 
| 
      
 184 
     | 
    
         
            +
                shared-mime-info (0.2.5)
         
     | 
| 
       181 
185 
     | 
    
         
             
                shoulda-matchers (2.4.0)
         
     | 
| 
       182 
186 
     | 
    
         
             
                  activesupport (>= 3.0.0)
         
     | 
| 
       183 
187 
     | 
    
         
             
                simplecov (0.8.2)
         
     | 
| 
         @@ -241,6 +245,7 @@ DEPENDENCIES 
     | 
|
| 
       241 
245 
     | 
    
         
             
              jquery-fileupload-rails!
         
     | 
| 
       242 
246 
     | 
    
         
             
              jquery-rails
         
     | 
| 
       243 
247 
     | 
    
         
             
              json_spec
         
     | 
| 
      
 248 
     | 
    
         
            +
              launchy
         
     | 
| 
       244 
249 
     | 
    
         
             
              mysql2
         
     | 
| 
       245 
250 
     | 
    
         
             
              poltergeist
         
     | 
| 
       246 
251 
     | 
    
         
             
              rails (= 4.0.1)
         
     | 
| 
         @@ -250,6 +255,7 @@ DEPENDENCIES 
     | 
|
| 
       250 
255 
     | 
    
         
             
              sass-rails (~> 4.0.0)
         
     | 
| 
       251 
256 
     | 
    
         
             
              sdoc
         
     | 
| 
       252 
257 
     | 
    
         
             
              selenium-webdriver
         
     | 
| 
      
 258 
     | 
    
         
            +
              shared-mime-info
         
     | 
| 
       253 
259 
     | 
    
         
             
              shoulda-matchers
         
     | 
| 
       254 
260 
     | 
    
         
             
              sqlite3
         
     | 
| 
       255 
261 
     | 
    
         
             
              turbolinks
         
     | 
| 
         @@ -47,6 +47,14 @@ $ -> 
     | 
|
| 
       47 
47 
     | 
    
         
             
                  data.submit()
         
     | 
| 
       48 
48 
     | 
    
         
             
                done: (e, data) ->
         
     | 
| 
       49 
49 
     | 
    
         
             
                  file = data.result
         
     | 
| 
       50 
     | 
    
         
            -
                   
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
                  if file.error
         
     | 
| 
      
 51 
     | 
    
         
            +
                    msg = $('<div class="alert alert-error" style="display: none">')
         
     | 
| 
      
 52 
     | 
    
         
            +
                      .append('<button type="button" class="close" data-dismiss="alert">×</button>')
         
     | 
| 
      
 53 
     | 
    
         
            +
                      .append('<h4><i class="icon-exclamation-sign"></i>エラー</h4>')
         
     | 
| 
      
 54 
     | 
    
         
            +
                      .append(file.name + 'は' + file.error)
         
     | 
| 
      
 55 
     | 
    
         
            +
                    $('#messages').append(msg)
         
     | 
| 
      
 56 
     | 
    
         
            +
                    msg.fadeIn('slow').delay(5000).fadeOut('slow')
         
     | 
| 
      
 57 
     | 
    
         
            +
                  else
         
     | 
| 
      
 58 
     | 
    
         
            +
                    $('#filename').val(file.name)
         
     | 
| 
      
 59 
     | 
    
         
            +
                    session.getDocument().setValue(file.source)
         
     | 
| 
       52 
60 
     | 
    
         
             
              )
         
     | 
| 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
       1 
2 
     | 
    
         
             
            require 'nkf'
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
4 
     | 
    
         
             
            class EditorController < ApplicationController
         
     | 
| 
         @@ -11,12 +12,18 @@ class EditorController < ApplicationController 
     | 
|
| 
       11 
12 
     | 
    
         | 
| 
       12 
13 
     | 
    
         
             
              def load_file
         
     | 
| 
       13 
14 
     | 
    
         
             
                f = params['load_file']
         
     | 
| 
      
 15 
     | 
    
         
            +
                mime_type = MIME.check(f.path)
         
     | 
| 
      
 16 
     | 
    
         
            +
                content_type = mime_type.try(:content_type) || f.content_type
         
     | 
| 
       14 
17 
     | 
    
         
             
                res = {
         
     | 
| 
       15 
18 
     | 
    
         
             
                  name: f.original_filename,
         
     | 
| 
       16 
     | 
    
         
            -
                  type:  
     | 
| 
      
 19 
     | 
    
         
            +
                  type: content_type,
         
     | 
| 
       17 
20 
     | 
    
         
             
                  size: f.size,
         
     | 
| 
       18 
     | 
    
         
            -
                  source: NKF.nkf('-w', f.read),
         
     | 
| 
       19 
21 
     | 
    
         
             
                }
         
     | 
| 
      
 22 
     | 
    
         
            +
                if /\Atext\/plain/ =~ content_type
         
     | 
| 
      
 23 
     | 
    
         
            +
                  res[:source] = NKF.nkf('-w', f.read)
         
     | 
| 
      
 24 
     | 
    
         
            +
                else
         
     | 
| 
      
 25 
     | 
    
         
            +
                  res[:error] = 'Rubyのプログラムではありません'
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
       20 
27 
     | 
    
         
             
                render json: res, content_type: request.format
         
     | 
| 
       21 
28 
     | 
    
         
             
              end
         
     | 
| 
       22 
29 
     | 
    
         
             
            end
         
     | 
    
        data/bin/smalruby-editor
    CHANGED
    
    | 
         @@ -1,8 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         
             
            # -*- coding: utf-8 -*-
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
      
 4 
     | 
    
         
            +
            require 'pathname'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       4 
6 
     | 
    
         
             
            ENV['RAILS_ENV'] = 'standalone'
         
     | 
| 
       5 
     | 
    
         
            -
            ENV['SECRET_KEY_BASE']  
     | 
| 
      
 7 
     | 
    
         
            +
            ENV['SECRET_KEY_BASE'] ||= 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
         
     | 
| 
      
 8 
     | 
    
         
            +
            ENV['SMALRUBY_EDITOR_HOME'] ||= Pathname('~/.smalruby-editor').expand_path.to_s
         
     | 
| 
       6 
9 
     | 
    
         | 
| 
       7 
10 
     | 
    
         
             
            APP_PATH = File.expand_path('../../config/application',  __FILE__)
         
     | 
| 
       8 
11 
     | 
    
         
             
            require_relative '../config/boot'
         
     | 
| 
         @@ -11,45 +14,11 @@ lib = File.expand_path('../../lib', __FILE__) 
     | 
|
| 
       11 
14 
     | 
    
         
             
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
       12 
15 
     | 
    
         
             
            require 'smalruby_editor'
         
     | 
| 
       13 
16 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            home_dir = Pathname('~/.smalruby-editor').expand_path
         
     | 
| 
       15 
     | 
    
         
            -
            ENV['SMALRUBY_EDITOR_HOME'] = home_dir.to_s
         
     | 
| 
       16 
     | 
    
         
            -
            log_dir, db_dir, config_dir, tmp_dir = *%w(log db config tmp).map { |s|
         
     | 
| 
       17 
     | 
    
         
            -
              home_dir.join(s)
         
     | 
| 
       18 
     | 
    
         
            -
            }.tap { |dir|
         
     | 
| 
       19 
     | 
    
         
            -
              FileUtils.mkdir_p(dir)
         
     | 
| 
       20 
     | 
    
         
            -
            }
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            database_yml_path = config_dir.join('database.yml')
         
     | 
| 
       23 
     | 
    
         
            -
            db_path = db_dir.join("#{ENV['RAILS_ENV']}.sqlite3").to_s
         
     | 
| 
       24 
     | 
    
         
            -
            if !File.exist?(database_yml_path)
         
     | 
| 
       25 
     | 
    
         
            -
              File.open(database_yml_path, 'w') do |f|
         
     | 
| 
       26 
     | 
    
         
            -
                f.write(<<-EOS)
         
     | 
| 
       27 
     | 
    
         
            -
            standalone:
         
     | 
| 
       28 
     | 
    
         
            -
              adapter: sqlite3
         
     | 
| 
       29 
     | 
    
         
            -
              database: #{db_path}
         
     | 
| 
       30 
     | 
    
         
            -
              pool: 5
         
     | 
| 
       31 
     | 
    
         
            -
              timeout: 5000
         
     | 
| 
       32 
     | 
    
         
            -
                EOS
         
     | 
| 
       33 
     | 
    
         
            -
              end
         
     | 
| 
       34 
     | 
    
         
            -
            end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
            #Create required tmp directories if not found
         
     | 
| 
       37 
     | 
    
         
            -
            %w(cache pids sessions sockets).each do |dir_to_make|
         
     | 
| 
       38 
     | 
    
         
            -
              FileUtils.mkdir_p(tmp_dir.join(dir_to_make))
         
     | 
| 
       39 
     | 
    
         
            -
            end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
17 
     | 
    
         
             
            Dir.chdir(File.expand_path('../../', APP_PATH))
         
     | 
| 
       42 
18 
     | 
    
         
             
            require 'rails/commands/server'
         
     | 
| 
       43 
19 
     | 
    
         | 
| 
       44 
20 
     | 
    
         
             
            module Rails
         
     | 
| 
       45 
21 
     | 
    
         
             
              class Server < ::Rack::Server
         
     | 
| 
       46 
     | 
    
         
            -
                def initialize(tmp_dir)
         
     | 
| 
       47 
     | 
    
         
            -
                  super()
         
     | 
| 
       48 
     | 
    
         
            -
                  set_environment
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                  @tmp_dir = tmp_dir
         
     | 
| 
       51 
     | 
    
         
            -
                end
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
22 
     | 
    
         
             
                def start
         
     | 
| 
       54 
23 
     | 
    
         
             
                  url = "#{options[:SSLEnable] ? 'https' : 'http'}://#{options[:Host]}:#{options[:Port]}"
         
     | 
| 
       55 
24 
     | 
    
         
             
                  puts "=> Booting #{ActiveSupport::Inflector.demodulize(server)}"
         
     | 
| 
         @@ -58,6 +27,24 @@ module Rails 
     | 
|
| 
       58 
27 
     | 
    
         
             
                  trap(:INT) { exit }
         
     | 
| 
       59 
28 
     | 
    
         
             
                  puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
         
     | 
| 
       60 
29 
     | 
    
         | 
| 
      
 30 
     | 
    
         
            +
                  unless options[:daemonize]
         
     | 
| 
      
 31 
     | 
    
         
            +
                    wrapped_app # touch the app so the logger is set up
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                    console = ActiveSupport::Logger.new($stdout)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    console.formatter = Rails.logger.formatter
         
     | 
| 
      
 35 
     | 
    
         
            +
                    console.level = Rails.logger.level
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                    Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  uri = "http://localhost:#{options[:Port]}"
         
     | 
| 
      
 41 
     | 
    
         
            +
                  launchy = Launchy.open(uri) do |exception|
         
     | 
| 
      
 42 
     | 
    
         
            +
                    puts "Attempted to open #{uri} and failed because #{exception}"
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  if launchy.respond_to?(:join)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    launchy.join
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       61 
48 
     | 
    
         
             
                  super
         
     | 
| 
       62 
49 
     | 
    
         
             
                ensure
         
     | 
| 
       63 
50 
     | 
    
         
             
                  # The '-h' option calls exit before @options is set.
         
     | 
| 
         @@ -67,19 +54,19 @@ module Rails 
     | 
|
| 
       67 
54 
     | 
    
         | 
| 
       68 
55 
     | 
    
         
             
                def default_options
         
     | 
| 
       69 
56 
     | 
    
         
             
                  super.merge({
         
     | 
| 
       70 
     | 
    
         
            -
                    Port:          
     | 
| 
      
 57 
     | 
    
         
            +
                    Port:         8087,
         
     | 
| 
       71 
58 
     | 
    
         
             
                    DoNotReverseLookup:  true,
         
     | 
| 
       72 
59 
     | 
    
         
             
                    environment:  (ENV['RAILS_ENV'] || ENV['RACK_ENV'] || "development").dup,
         
     | 
| 
       73 
60 
     | 
    
         
             
                    daemonize:    false,
         
     | 
| 
       74 
61 
     | 
    
         
             
                    debugger:     false,
         
     | 
| 
       75 
     | 
    
         
            -
                    pid:           
     | 
| 
      
 62 
     | 
    
         
            +
                    pid:          Pathname(ENV['SMALRUBY_EDITOR_HOME']).join("tmp/pids/server.pid").to_s,
         
     | 
| 
       76 
63 
     | 
    
         
             
                    config:       File.expand_path("config.ru")
         
     | 
| 
       77 
64 
     | 
    
         
             
                  })
         
     | 
| 
       78 
65 
     | 
    
         
             
                end
         
     | 
| 
       79 
66 
     | 
    
         
             
              end
         
     | 
| 
       80 
67 
     | 
    
         
             
            end
         
     | 
| 
       81 
68 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
            Rails::Server.new 
     | 
| 
      
 69 
     | 
    
         
            +
            Rails::Server.new.tap do |server|
         
     | 
| 
       83 
70 
     | 
    
         
             
              require APP_PATH
         
     | 
| 
       84 
71 
     | 
    
         
             
              Dir.chdir(Rails.application.root)
         
     | 
| 
       85 
72 
     | 
    
         
             
              server.start
         
     | 
| 
         @@ -4,7 +4,9 @@ SmalrubyEditor::Application.configure do 
     | 
|
| 
       4 
4 
     | 
    
         
             
              if !ENV['SMALRUBY_EDITOR_HOME']
         
     | 
| 
       5 
5 
     | 
    
         
             
                fail 'you must set SMALRUBY_EDITOR_HOME environment variable.'
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              home_dir = SmalrubyEditor.create_home_directory
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       8 
10 
     | 
    
         
             
              config.paths.add 'config/database', with: home_dir.join('config/database.yml')
         
     | 
| 
       9 
11 
     | 
    
         
             
              config.paths.add 'log', with: home_dir.join("log/#{Rails.env}.log")
         
     | 
| 
       10 
12 
     | 
    
         
             
              config.paths.add 'tmp', with: home_dir.join('tmp')
         
     | 
    
        data/lib/smalruby_editor.rb
    CHANGED
    
    | 
         @@ -1,4 +1,32 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'smalruby_editor/version'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            module SmalrubyEditor
         
     | 
| 
      
 4 
     | 
    
         
            +
              def create_home_directory(home_dir = nil)
         
     | 
| 
      
 5 
     | 
    
         
            +
                if home_dir.blank?
         
     | 
| 
      
 6 
     | 
    
         
            +
                  home_dir = Pathname(ENV['SMALRUBY_EDITOR_HOME'] || '~/.smalruby-editor').expand_path
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                %w(log db config tmp/cache tmp/pids tmp/sessions tmp/sockets).map { |s|
         
     | 
| 
      
 10 
     | 
    
         
            +
                  home_dir.join(s)
         
     | 
| 
      
 11 
     | 
    
         
            +
                }.each do |dir|
         
     | 
| 
      
 12 
     | 
    
         
            +
                  FileUtils.mkdir_p(dir)
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                database_yml_path = home_dir.join('config', 'database.yml')
         
     | 
| 
      
 16 
     | 
    
         
            +
                db_path = home_dir.join('db', 'standalone.sqlite3')
         
     | 
| 
      
 17 
     | 
    
         
            +
                if !File.exist?(database_yml_path)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  File.open(database_yml_path, 'w') do |f|
         
     | 
| 
      
 19 
     | 
    
         
            +
                    f.write(<<-EOS)
         
     | 
| 
      
 20 
     | 
    
         
            +
            standalone:
         
     | 
| 
      
 21 
     | 
    
         
            +
              adapter: sqlite3
         
     | 
| 
      
 22 
     | 
    
         
            +
              database: #{db_path}
         
     | 
| 
      
 23 
     | 
    
         
            +
              pool: 5
         
     | 
| 
      
 24 
     | 
    
         
            +
              timeout: 5000
         
     | 
| 
      
 25 
     | 
    
         
            +
                    EOS
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                home_dir
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
              module_function :create_home_directory
         
     | 
| 
       4 
32 
     | 
    
         
             
            end
         
     | 
    
        data/smalruby-editor.gemspec
    CHANGED
    
    
| 
         @@ -42,7 +42,7 @@ 
     | 
|
| 
       42 
42 
     | 
    
         
             
                かつ JavaScriptによるリクエストが終わるまで待つ
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                ならば "テキストエディタ" に "files/01.rb" を読み込む
         
     | 
| 
       45 
     | 
    
         
            -
                かつ "プログラム名の入力欄"  
     | 
| 
      
 45 
     | 
    
         
            +
                かつ "プログラム名の入力欄" は "01.rb" である
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
              シナリオ: プログラムを入力済み状態でプログラムを読み込む
         
     | 
| 
       48 
48 
     | 
    
         
             
                前提 "エディタ" 画面を表示する
         
     | 
| 
         @@ -55,4 +55,14 @@ 
     | 
|
| 
       55 
55 
     | 
    
         
             
                かつ JavaScriptによるリクエストが終わるまで待つ
         
     | 
| 
       56 
56 
     | 
    
         | 
| 
       57 
57 
     | 
    
         
             
                ならば "テキストエディタ" に "files/01.rb" を読み込む
         
     | 
| 
       58 
     | 
    
         
            -
                かつ "プログラム名の入力欄"  
     | 
| 
      
 58 
     | 
    
         
            +
                かつ "プログラム名の入力欄" は "01.rb" である
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              シナリオ: ロードボタンを押して画像を読み込もうとする
         
     | 
| 
      
 61 
     | 
    
         
            +
                前提 "エディタ" 画面を表示する
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                もし "files/favicon.ico" をアップロードする
         
     | 
| 
      
 64 
     | 
    
         
            +
                かつ JavaScriptによるリクエストが終わるまで待つ
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                ならば "テキストエディタ" のプログラムは "" である
         
     | 
| 
      
 67 
     | 
    
         
            +
                かつ "プログラム名の入力欄" は "" である
         
     | 
| 
      
 68 
     | 
    
         
            +
                かつ "メッセージ" に "favicon.icoはRubyのプログラムではありません" を含む
         
     | 
| 
         @@ -30,23 +30,44 @@ describe EditorController do 
     | 
|
| 
       30 
30 
     | 
    
         
             
              end
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
              describe "プログラムを読み込む (POST 'load_file')" do
         
     | 
| 
       33 
     | 
    
         
            -
                let(:load_file) { fixture_file_upload('files/01.rb') }
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
33 
     | 
    
         
             
                before do
         
     | 
| 
       36 
34 
     | 
    
         
             
                  post 'load_file', load_file: load_file
         
     | 
| 
       37 
35 
     | 
    
         
             
                end
         
     | 
| 
       38 
36 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                 
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                   
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                     
     | 
| 
       46 
     | 
    
         
            -
                     
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                describe '正常系' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  let(:load_file) { fixture_file_upload('files/01.rb', 'text/plain') }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  it { expect(response).to be_success }
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  it 'アップロードされたプログラムの情報をJSON形式でダウンロードできる' do
         
     | 
| 
      
 43 
     | 
    
         
            +
                    load_file.rewind
         
     | 
| 
      
 44 
     | 
    
         
            +
                    file = {
         
     | 
| 
      
 45 
     | 
    
         
            +
                      name: load_file.original_filename,
         
     | 
| 
      
 46 
     | 
    
         
            +
                      type: load_file.content_type,
         
     | 
| 
      
 47 
     | 
    
         
            +
                      size: load_file.size,
         
     | 
| 
      
 48 
     | 
    
         
            +
                      source: load_file.read.force_encoding('utf-8'),
         
     | 
| 
      
 49 
     | 
    
         
            +
                    }
         
     | 
| 
      
 50 
     | 
    
         
            +
                    expect(response.body).to be_json_eql(file.to_json)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  end
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                describe '異常系' do
         
     | 
| 
      
 55 
     | 
    
         
            +
                  context '画像をアップロードした場合' do
         
     | 
| 
      
 56 
     | 
    
         
            +
                    let(:load_file) { fixture_file_upload('files/favicon.ico',
         
     | 
| 
      
 57 
     | 
    
         
            +
                                                          'application/octet-stream') }
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                    it { expect(response).to be_success }
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                    it 'エラーを返す' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                      file = {
         
     | 
| 
      
 63 
     | 
    
         
            +
                        name: load_file.original_filename,
         
     | 
| 
      
 64 
     | 
    
         
            +
                        error: 'Rubyのプログラムではありません',
         
     | 
| 
      
 65 
     | 
    
         
            +
                      }
         
     | 
| 
      
 66 
     | 
    
         
            +
                      file.each do |path, value|
         
     | 
| 
      
 67 
     | 
    
         
            +
                        expect(response.body).to include_json(value.to_json).at_path(path.to_s)
         
     | 
| 
      
 68 
     | 
    
         
            +
                      end
         
     | 
| 
      
 69 
     | 
    
         
            +
                    end
         
     | 
| 
      
 70 
     | 
    
         
            +
                  end
         
     | 
| 
       50 
71 
     | 
    
         
             
                end
         
     | 
| 
       51 
72 
     | 
    
         
             
              end
         
     | 
| 
       52 
73 
     | 
    
         
             
            end
         
     | 
| 
         Binary file 
     | 
| 
         @@ -0,0 +1,64 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # -*- coding: utf-8 -*-
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative '../spec_helper'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'smalruby_editor'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            describe SmalrubyEditor do
         
     | 
| 
      
 6 
     | 
    
         
            +
              describe '.create_home_directory' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                before(:all) do
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @home_dir = Pathname(Dir.tmpdir).join('.smalruby-editor')
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                shared_examples 'ホームディレクトリを作成する', create_home_directory: true do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  after(:all) do
         
     | 
| 
      
 13 
     | 
    
         
            +
                    FileUtils.rm_rf(@home_dir)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  it 'ホームディレクトリを作成する' do
         
     | 
| 
      
 17 
     | 
    
         
            +
                    expect(@home_dir).to be_directory
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  describe 'ホームディレクトリ' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                    %w(config db log tmp tmp/cache tmp/pids tmp/sessions tmp/sockets).each do |dir|
         
     | 
| 
      
 22 
     | 
    
         
            +
                      it "#{dir}ディレクトリを作成する" do
         
     | 
| 
      
 23 
     | 
    
         
            +
                        expect(@home_dir.join(dir)).to be_directory
         
     | 
| 
      
 24 
     | 
    
         
            +
                      end
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                    describe 'configディレクトリ' do
         
     | 
| 
      
 28 
     | 
    
         
            +
                      let(:path) { @home_dir.join('config', 'database.yml') }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                      it 'database.ymlを作成する' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                        expect(path).to be_exist
         
     | 
| 
      
 32 
     | 
    
         
            +
                      end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                      it 'database.ymlの内容が正しい' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                        expect(path.read).to eq(<<-EOS.strip_heredoc)
         
     | 
| 
      
 36 
     | 
    
         
            +
                        standalone:
         
     | 
| 
      
 37 
     | 
    
         
            +
                          adapter: sqlite3
         
     | 
| 
      
 38 
     | 
    
         
            +
                          database: #{@home_dir.join('db', 'standalone.sqlite3')}
         
     | 
| 
      
 39 
     | 
    
         
            +
                          pool: 5
         
     | 
| 
      
 40 
     | 
    
         
            +
                          timeout: 5000
         
     | 
| 
      
 41 
     | 
    
         
            +
                      EOS
         
     | 
| 
      
 42 
     | 
    
         
            +
                      end
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                it '戻り値は作成したホームディレクトリである' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  expect(SmalrubyEditor.create_home_directory(@home_dir)).to eq(@home_dir)
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                context '引数を指定した場合', create_home_directory: true do
         
     | 
| 
      
 52 
     | 
    
         
            +
                  before(:all) do
         
     | 
| 
      
 53 
     | 
    
         
            +
                    SmalrubyEditor.create_home_directory(@home_dir)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                describe '引数を指定しない場合は環境変数SMALRUBY_EDITOR_HOMEに従う', create_home_directory: true do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  before(:all) do
         
     | 
| 
      
 59 
     | 
    
         
            +
                    ENV['SMALRUBY_EDITOR_HOME'] = @home_dir.to_s
         
     | 
| 
      
 60 
     | 
    
         
            +
                    SmalrubyEditor.create_home_directory
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/steps/editor_steps.rb
    CHANGED
    
    | 
         @@ -1,106 +1,123 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
               
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
            step ':name  
     | 
| 
       34 
     | 
    
         
            -
               
     | 
| 
       35 
     | 
    
         
            -
            end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
            step ':name  
     | 
| 
       38 
     | 
    
         
            -
               
     | 
| 
       39 
     | 
    
         
            -
            end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
            step ': 
     | 
| 
       42 
     | 
    
         
            -
               
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
               
     | 
| 
       52 
     | 
    
         
            -
            end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
            step ': 
     | 
| 
       55 
     | 
    
         
            -
               
     | 
| 
       56 
     | 
    
         
            -
            end
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
            step ': 
     | 
| 
       59 
     | 
    
         
            -
               
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
            end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
            step ' 
     | 
| 
       70 
     | 
    
         
            -
              # TODO
         
     | 
| 
       71 
     | 
    
         
            -
            end
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
            step ' 
     | 
| 
       74 
     | 
    
         
            -
              #  
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
               
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
               
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
               
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
               
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
               
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            +
                id: 'messages',
         
     | 
| 
      
 29 
     | 
    
         
            +
                selector: '#messages',
         
     | 
| 
      
 30 
     | 
    
         
            +
              },
         
     | 
| 
      
 31 
     | 
    
         
            +
            }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            step ':name にアクセスする' do |name|
         
     | 
| 
      
 34 
     | 
    
         
            +
              visit name_info[name][:path]
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            step ':name が表示されていること' do |name|
         
     | 
| 
      
 38 
     | 
    
         
            +
              expect(page).to have_selector(name_info[name][:selector])
         
     | 
| 
      
 39 
     | 
    
         
            +
            end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            step ':name 画面を表示する' do |name|
         
     | 
| 
      
 42 
     | 
    
         
            +
              visit name_info[name][:path]
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            step ':text_editor にプログラムを入力済みである:' do |text_editor, source|
         
     | 
| 
      
 46 
     | 
    
         
            +
              page.execute_script(<<-JS)
         
     | 
| 
      
 47 
     | 
    
         
            +
                ace.edit('#{name_info[text_editor][:id]}')
         
     | 
| 
      
 48 
     | 
    
         
            +
                  .getSession()
         
     | 
| 
      
 49 
     | 
    
         
            +
                  .getDocument()
         
     | 
| 
      
 50 
     | 
    
         
            +
                  .setValue('#{source}')
         
     | 
| 
      
 51 
     | 
    
         
            +
              JS
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            step 'プログラムの名前に :filename を指定する' do |filename|
         
     | 
| 
      
 55 
     | 
    
         
            +
              fill_in('filename', with: filename)
         
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            step ':name をクリックする' do |name|
         
     | 
| 
      
 59 
     | 
    
         
            +
              click_button(name_info[name][:id])
         
     | 
| 
      
 60 
     | 
    
         
            +
            end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            step ':filename をダウンロードする' do |filename|
         
     | 
| 
      
 63 
     | 
    
         
            +
              expect(page.response_headers['Content-Disposition'])
         
     | 
| 
      
 64 
     | 
    
         
            +
                .to eq("attachment; filename=\"#{filename}\"")
         
     | 
| 
      
 65 
     | 
    
         
            +
              expect(page.response_headers['Content-Type'])
         
     | 
| 
      
 66 
     | 
    
         
            +
                .to eq('text/plain; charset=utf-8')
         
     | 
| 
      
 67 
     | 
    
         
            +
            end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            step 'ダウンロードしたファイルの内容が正しい:' do |source|
         
     | 
| 
      
 70 
     | 
    
         
            +
              # TODO
         
     | 
| 
      
 71 
     | 
    
         
            +
            end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            step 'ダウンロードしない' do
         
     | 
| 
      
 74 
     | 
    
         
            +
              # TODO
         
     | 
| 
      
 75 
     | 
    
         
            +
            end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            step ':name にフォーカスが移る' do |name|
         
     | 
| 
      
 78 
     | 
    
         
            +
              # 現在のPhantomJSでは$(':focus')は動作しない
         
     | 
| 
      
 79 
     | 
    
         
            +
              # https://github.com/netzpirat/guard-jasmine/issues/48
         
     | 
| 
      
 80 
     | 
    
         
            +
              expect(page.evaluate_script(<<-JS)).to be_true
         
     | 
| 
      
 81 
     | 
    
         
            +
                $('#filename').get(0) == document.activeElement
         
     | 
| 
      
 82 
     | 
    
         
            +
              JS
         
     | 
| 
      
 83 
     | 
    
         
            +
            end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            step ':filename をアップロードする' do |filename|
         
     | 
| 
      
 86 
     | 
    
         
            +
              page.execute_script("$('#load-file').show()")
         
     | 
| 
      
 87 
     | 
    
         
            +
              attach_file('load-file', Pathname(fixture_path).join(filename))
         
     | 
| 
      
 88 
     | 
    
         
            +
            end
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
            step ':text_editor に :filename を読み込む' do |text_editor, filename|
         
     | 
| 
      
 91 
     | 
    
         
            +
              expect(page.evaluate_script(<<-JS)).to eq(Pathname(fixture_path).join(filename).read)
         
     | 
| 
      
 92 
     | 
    
         
            +
                ace.edit('#{name_info[text_editor][:id]}')
         
     | 
| 
      
 93 
     | 
    
         
            +
                  .getSession()
         
     | 
| 
      
 94 
     | 
    
         
            +
                  .getDocument()
         
     | 
| 
      
 95 
     | 
    
         
            +
                  .getValue()
         
     | 
| 
      
 96 
     | 
    
         
            +
              JS
         
     | 
| 
      
 97 
     | 
    
         
            +
            end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
            step 'JavaScriptによるリクエストが終わるまで待つ' do
         
     | 
| 
      
 100 
     | 
    
         
            +
              start_time = Time.now
         
     | 
| 
      
 101 
     | 
    
         
            +
              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
         
     | 
| 
      
 102 
     | 
    
         
            +
                sleep 1
         
     | 
| 
      
 103 
     | 
    
         
            +
              end
         
     | 
| 
      
 104 
     | 
    
         
            +
            end
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
            step ':text_editor のプログラムは :value である' do |text_editor, value|
         
     | 
| 
      
 107 
     | 
    
         
            +
              expect(page.evaluate_script(<<-JS)).to eq(value)
         
     | 
| 
      
 108 
     | 
    
         
            +
                ace.edit('#{name_info[text_editor][:id]}')
         
     | 
| 
      
 109 
     | 
    
         
            +
                  .getSession()
         
     | 
| 
      
 110 
     | 
    
         
            +
                  .getDocument()
         
     | 
| 
      
 111 
     | 
    
         
            +
                  .getValue()
         
     | 
| 
      
 112 
     | 
    
         
            +
              JS
         
     | 
| 
      
 113 
     | 
    
         
            +
            end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
            step ':name は :value である' do |name, value|
         
     | 
| 
      
 116 
     | 
    
         
            +
              expect(page.evaluate_script(<<-JS)).to eq(value)
         
     | 
| 
      
 117 
     | 
    
         
            +
                $('#{name_info[name][:selector]}').val()
         
     | 
| 
      
 118 
     | 
    
         
            +
              JS
         
     | 
| 
      
 119 
     | 
    
         
            +
            end
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
            step ':name に :message を含む' do |name, message|
         
     | 
| 
      
 122 
     | 
    
         
            +
              expect(page.find(name_info[name][:selector])).to have_content(message)
         
     | 
| 
      
 123 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: smalruby-editor
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Kouji Takao
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-12-01 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -178,6 +178,20 @@ dependencies: 
     | 
|
| 
       178 
178 
     | 
    
         
             
                - - '>='
         
     | 
| 
       179 
179 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       180 
180 
     | 
    
         
             
                    version: '0'
         
     | 
| 
      
 181 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 182 
     | 
    
         
            +
              name: launchy
         
     | 
| 
      
 183 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 184 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 185 
     | 
    
         
            +
                - - '>='
         
     | 
| 
      
 186 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 187 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 188 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 189 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 190 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 191 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 192 
     | 
    
         
            +
                - - '>='
         
     | 
| 
      
 193 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 194 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
       181 
195 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       182 
196 
     | 
    
         
             
              name: bundler
         
     | 
| 
       183 
197 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -288,15 +302,17 @@ files: 
     | 
|
| 
       288 
302 
     | 
    
         
             
            - spec/acceptance/editor.feature
         
     | 
| 
       289 
303 
     | 
    
         
             
            - spec/controllers/editor_controller_spec.rb
         
     | 
| 
       290 
304 
     | 
    
         
             
            - spec/fixtures/files/01.rb
         
     | 
| 
      
 305 
     | 
    
         
            +
            - spec/fixtures/files/favicon.ico
         
     | 
| 
       291 
306 
     | 
    
         
             
            - spec/helpers/editor_helper_spec.rb
         
     | 
| 
      
 307 
     | 
    
         
            +
            - spec/lib/smalruby_editor_spec.rb
         
     | 
| 
       292 
308 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       293 
309 
     | 
    
         
             
            - spec/steps/editor_steps.rb
         
     | 
| 
       294 
310 
     | 
    
         
             
            - vendor/assets/javascripts/.keep
         
     | 
| 
       295 
311 
     | 
    
         
             
            - vendor/assets/stylesheets/.keep
         
     | 
| 
       296 
     | 
    
         
            -
            - public/assets/application- 
     | 
| 
       297 
     | 
    
         
            -
            - public/assets/application- 
     | 
| 
       298 
     | 
    
         
            -
            - public/assets/application- 
     | 
| 
       299 
     | 
    
         
            -
            - public/assets/application- 
     | 
| 
      
 312 
     | 
    
         
            +
            - public/assets/application-1cd3f5170c998a23c96c9c853c2519a0.js
         
     | 
| 
      
 313 
     | 
    
         
            +
            - public/assets/application-1cd3f5170c998a23c96c9c853c2519a0.js.gz
         
     | 
| 
      
 314 
     | 
    
         
            +
            - public/assets/application-7dfa749c08d706f7273aa6f60cfafefa.css
         
     | 
| 
      
 315 
     | 
    
         
            +
            - public/assets/application-7dfa749c08d706f7273aa6f60cfafefa.css.gz
         
     | 
| 
       300 
316 
     | 
    
         
             
            - public/assets/favicon-c7ae857bb9d06de8742ae2d337157e83.ico
         
     | 
| 
       301 
317 
     | 
    
         
             
            - public/assets/loading-e8e6dd7833131c92a6c3b9c8ccc6a6ac.gif
         
     | 
| 
       302 
318 
     | 
    
         
             
            - public/assets/manifest-321187c7a24ba9122c18505055065b0f.json
         
     | 
| 
         @@ -362,6 +378,8 @@ test_files: 
     | 
|
| 
       362 
378 
     | 
    
         
             
            - spec/acceptance/editor.feature
         
     | 
| 
       363 
379 
     | 
    
         
             
            - spec/controllers/editor_controller_spec.rb
         
     | 
| 
       364 
380 
     | 
    
         
             
            - spec/fixtures/files/01.rb
         
     | 
| 
      
 381 
     | 
    
         
            +
            - spec/fixtures/files/favicon.ico
         
     | 
| 
       365 
382 
     | 
    
         
             
            - spec/helpers/editor_helper_spec.rb
         
     | 
| 
      
 383 
     | 
    
         
            +
            - spec/lib/smalruby_editor_spec.rb
         
     | 
| 
       366 
384 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       367 
385 
     | 
    
         
             
            - spec/steps/editor_steps.rb
         
     |