Skip to content

Commit

Permalink
Upload file names as part of the source code
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanroock committed Jun 2, 2011
1 parent c60408b commit 3151b62
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/shell_wrapper.rb
Expand Up @@ -75,7 +75,7 @@ def files_in_dir dir, regexp_pattern=nil
def files_in_dir_tree dir, regexp_pattern=nil
Dir.glob("#{dir}/**/*").find_all{|entry|
file_matches_regexp? entry, regexp_pattern
}
}.sort
end

def file_matches_regexp? dir_entry, regexp_pattern
Expand Down
7 changes: 6 additions & 1 deletion app/state_reader.rb
Expand Up @@ -56,7 +56,12 @@ def read_next_state
def read_source_files state_dir
files = @shell.files_in_dir_tree state_dir
source_files = files.find_all{|file| @filename_formatter.source_file_in_state_dir? file}
source_files.collect {|file| @shell.read_file file}
marker = "=========="
source_files.collect {|file|
filename = @filename_formatter.extract_last_path_item file
code = @shell.read_file(file)
"#{marker} #{filename} #{marker}\n\n#{code}"
}
end

def fill_state_with_properties state, properties
Expand Down
1 change: 1 addition & 0 deletions app/uploader.rb
@@ -1,3 +1,4 @@
require 'json'
require 'state'
require 'state_reader'
require 'progress'
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/shell_wrapper_spec.rb
Expand Up @@ -20,10 +20,10 @@
@shell.files_in_dir('myDir', '.*\.rb').should == ['file1.rb']
end

it "should filter files by regex pattern recursivly" do
Dir.should_receive(:glob).with('myDir/**/*').and_return ['file1.rb', 'file2.py']
it "should filter files by regex pattern recursivly and sort result alphabetically" do
Dir.should_receive(:glob).with('myDir/**/*').and_return ['file3.rb', 'file2.rb', 'file1.py']
File.should_receive(:file?).any_number_of_times.and_return true
@shell.files_in_dir_tree('myDir', '.*\.rb').should == ['file1.rb']
@shell.files_in_dir_tree('myDir', '.*\.rb').should == ['file2.rb', "file3.rb"]
end

it "should omit . and .. from dir list" do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/state_reader_spec.rb
Expand Up @@ -19,7 +19,7 @@
@shell_mock.should_receive(:read_properties).with(".codersdojo/id0815/#{@state_dir_prefix}0/info.yml").and_return('return_code' => 256)
state = @state_reader.read_next_state
state.time.should == @a_time
state.files.should == ["source code"]
state.files.should == ["========== file.rb ==========\n\nsource code"]
state.result.should == "result"
state.return_code.should == 256
@state_reader.next_step.should == 1
Expand Down

0 comments on commit 3151b62

Please sign in to comment.