Skip to content

Commit

Permalink
Merge pull request #123 from ONLYOFFICE/feature/ability-to-run-any-files
Browse files Browse the repository at this point in the history
Add ability to run any files from any part of project
  • Loading branch information
ShockwaveNN committed Feb 16, 2016
2 parents d21d1fb + e90ed5e commit 12475fb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## 1.8
### New features
* Test list now shown not only `spec` and `RSpec` folder, but all project folders
* Ability to run any file, not only `_spec.rb`. Currently only supported `_spec.rb` and generic `.rb` files

## 1.7.1
* Fix order in which project are pulled. If there was new dependencies in `testing-shared` - they will be included in OnlineDocuments

Expand Down
15 changes: 1 addition & 14 deletions app/helpers/runner_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def directory_hash(path, name = nil)
data[:children] = children = []
data[:path] = path
Dir.foreach(path).sort.each do |entry|
next if entry == '..' || entry == '.'
next if entry.start_with?('.')
full_path = File.join(path, entry)
if File.directory?(full_path)
children << directory_hash(full_path, entry)
Expand All @@ -28,19 +28,6 @@ def get_subtest_by_path(path_to_test)
file_tests
end

def get_file_path(file_name, project)
project_path = if project == :docs
DOCS_TESTS_PATH
elsif project == :tm
TEAMLAB_TESTS_PATH
end
path_to_test = ''
Find.find(project_path) do |path|
path_to_test = path if path =~ /#{file_name}/
end
path_to_test.gsub(project_path, '')
end

def get_list_branches(project_path)
system_message = `cd #{project_path}; git pull --prune; git checkout develop; git branch -a`
branches = []
Expand Down
13 changes: 11 additions & 2 deletions app/server/managers/test_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

module TestManager
TEST_SPOT_USER_NAME = 'nct-at'

# Determine which command is used to run test
# @return [String] command to run test. Empty if not supported.
def command_executioner(test)
return 'rspec' if test.end_with?('_spec.rb')
return 'ruby' if test.end_with?('rb')
''
end

def start_test_on_server(test_path, options)
full_start_command = generate_run_test_command(test_path, options)
full_start_command = generate_run_test_command(test_path.gsub('~', '$HOME'), options)
@ssh_pid = Process.spawn(full_start_command, out: [server_log_path, 'w'])
Process.wait(@ssh_pid)
full_start_command
Expand All @@ -24,7 +33,7 @@ def stop_test
end

def generate_run_test_command(test, options)
execute_docker_command("source ~/.rvm/scripts/rvm; #{options.create_options}; #{open_folder_with_project(test)} && export DISPLAY=:0.0 && rspec '#{test}' #{save_to_html} 2>&1; #{kill_all_browsers_on_server}")
execute_docker_command("source ~/.rvm/scripts/rvm; #{options.create_options}; #{open_folder_with_project(test)} && export DISPLAY=:0.0 && #{command_executioner(test)} '#{test}' #{save_to_html} 2>&1; #{kill_all_browsers_on_server}")
end

def open_folder_with_project(test_path)
Expand Down
25 changes: 12 additions & 13 deletions app/views/runner/show_tests.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
<% show_file_tree(current_child, project) %>
<% else %>
<% unless current_child.has_key?(:children) %>
<% if current_child[:name].include?('_spec.rb') %>
<% child_name = current_child[:name].split('.')[0] %>
<div class="file">
<div class="add-button-file active" data-test="<%= current_child[:path] %>" style="">add</div>
<div class="file-name"><i class="glyphicon glyphicon-file"></i><%= child_name %><i class="add-file glyphicon glyphicon-plus-sign"></i></div>
</div>
<% end %>
<% child_name = current_child[:name] %>
<div class="file">
<div class="add-button-file active" data-test="<%= current_child[:path] %>" style="">add</div>
<div class="file-name"><i class="glyphicon glyphicon-file"></i><%= child_name %>
<i class="add-file glyphicon glyphicon-plus-sign"></i></div>
</div>
<% end %>
<% end %>
<% end %>
Expand All @@ -33,26 +32,26 @@
<% if @client %>
<% if @client.project == 'docs' %>
<div class="tab-pane active" id="docs">
<% show_file_tree(directory_hash(DOCS_TESTS_PATH)[:children], :docs) %>
<% show_file_tree(directory_hash(DOCS_PROJECT_PATH)[:children], :docs) %>
</div>
<div class="tab-pane" id="teamlab">
<% show_file_tree(directory_hash(TEAMLAB_TESTS_PATH)[:children], :tm) %>
<% show_file_tree(directory_hash(DOCS_PROJECT_PATH)[:children], :tm) %>
</div>
<% end %>
<% if @client.project == 'teamlab' %>
<div class="tab-pane" id="docs">
<% show_file_tree(directory_hash(DOCS_TESTS_PATH)[:children], :docs) %>
<% show_file_tree(directory_hash(DOCS_PROJECT_PATH)[:children], :docs) %>
</div>
<div class="tab-pane active" id="teamlab">
<% show_file_tree(directory_hash(TEAMLAB_TESTS_PATH)[:children], :tm) %>
<% show_file_tree(directory_hash(TEAMLAB_PROJECT_PATH)[:children], :tm) %>
</div>
<% end %>

<% else %>
<div class="tab-pane <%= check_active('docs') %>" id="docs">
<% show_file_tree(directory_hash(DOCS_TESTS_PATH)[:children], :docs) %>
<% show_file_tree(directory_hash(DOCS_PROJECT_PATH)[:children], :docs) %>
</div>
<div class="tab-pane <%= check_active('teamlab') %>" id="teamlab">
<% show_file_tree(directory_hash(TEAMLAB_TESTS_PATH)[:children], :tm) %>
<% show_file_tree(directory_hash(TEAMLAB_PROJECT_PATH)[:children], :tm) %>
</div>
<% end %>
2 changes: 0 additions & 2 deletions config/initializers/constants.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
DOCS_PROJECT_PATH = "/#{ENV['HOME']}/RubymineProjects/OnlineDocuments"
TEAMLAB_PROJECT_PATH = "/#{ENV['HOME']}/RubymineProjects/TeamLab"
DOCS_TESTS_PATH = "/#{ENV['HOME']}/RubymineProjects/OnlineDocuments/spec"
TEAMLAB_TESTS_PATH = "/#{ENV['HOME']}/RubymineProjects/TeamLab/Rspec"
SERVERS_LOGS_PATH = 'app/server/logs'
DOCS_PROJECT_NAME = 'OnlineDocuments'
TEAMLAB_PROJECT_NAME = 'TeamLab'
Expand Down

0 comments on commit 12475fb

Please sign in to comment.