-
-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fixtures to aruba #224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
require 'rspec/expectations' | ||
require 'aruba' | ||
require 'aruba/config' | ||
require 'ostruct' | ||
require 'pathname' | ||
|
||
Dir.glob( File.join( File.expand_path( '../matchers' , __FILE__ ) , '*.rb' ) ).each { |rb| require rb } | ||
|
||
|
@@ -21,20 +23,32 @@ module Api | |
# @example Single file name | ||
# | ||
# # => <path>/tmp/aruba/file | ||
# absolute_path('file') | ||
# expand_path('file') | ||
# | ||
# @example Single Dot | ||
# | ||
# # => <path>/tmp/aruba | ||
# absolute_path('.') | ||
# expand_path('.') | ||
# | ||
# @example Join and Expand path | ||
# | ||
# # => <path>/tmp/aruba/path/file | ||
# absolute_path('path', 'file') | ||
# expand_path('path', 'file') | ||
# | ||
def expand_path(*args) | ||
if %r{^#{fixtures_path_prefix}/} === args.first | ||
File.join fixtures_directory, args.shift.sub(%r{^#{fixtures_path_prefix}/}, ''), *args | ||
else | ||
in_current_directory { File.expand_path File.join(*args) } | ||
end | ||
end | ||
|
||
# @private | ||
# @deprecated | ||
def absolute_path(*args) | ||
in_current_directory { File.expand_path File.join(*args) } | ||
warn('The use of "absolute_path" is deprecated. Use "expand_path" instead') | ||
|
||
expand_path(*args) | ||
end | ||
|
||
# Execute block in current directory | ||
|
@@ -126,7 +140,7 @@ def touch_file(*args) | |
{} | ||
end | ||
|
||
args = args.map { |p| absolute_path(p) } | ||
args = args.map { |p| expand_path(p) } | ||
args.each { |p| _mkdir(File.dirname(p)) } | ||
|
||
FileUtils.touch(args, options) | ||
|
@@ -194,7 +208,7 @@ def filesystem_permissions(*args) | |
mode | ||
end | ||
|
||
args = args.map { |p| absolute_path(p) } | ||
args = args.map { |p| expand_path(p) } | ||
args.each { |p| raise "Expected #{p} to be present" unless FileTest.exists?(p) } | ||
|
||
FileUtils.chmod(mode, args, options) | ||
|
@@ -224,7 +238,7 @@ def check_filesystem_permissions(*args) | |
expected_permissions = args.shift | ||
expected_result = args.pop | ||
|
||
args = args.map { |p| absolute_path(p) } | ||
args = args.map { |p| expand_path(p) } | ||
|
||
args.each do |p| | ||
raise "Expected #{p} to be present" unless FileTest.exists?(p) | ||
|
@@ -269,7 +283,7 @@ def remove_file(*args) | |
{} | ||
end | ||
|
||
args = args.map { |p| absolute_path(p) } | ||
args = args.map { |p| expand_path(p) } | ||
|
||
FileUtils.rm(args, options) | ||
end | ||
|
@@ -322,7 +336,7 @@ def remove_directory(*args) | |
{} | ||
end | ||
|
||
args = args.map { |p| absolute_path(p) } | ||
args = args.map { |p| expand_path(p) } | ||
|
||
FileUtils.rm_r(args, options) | ||
end | ||
|
@@ -788,6 +802,40 @@ def io_wait | |
@aruba_io_wait_seconds || DEFAULT_IO_WAIT_SECONDS | ||
end | ||
|
||
DEFAULT_ROOT_DIRECTORY = Dir.getwd | ||
|
||
# The root directory of aruba | ||
def root_directory | ||
@aruba_root_directory ||= DEFAULT_ROOT_DIRECTORY | ||
end | ||
|
||
# Path prefix for fixtures | ||
def fixtures_path_prefix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making the fixture prefix character configurable via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. changed. |
||
'%' | ||
end | ||
|
||
DEFAULT_FIXTURES_DIRECTORY = 'fixtures' | ||
|
||
# The path to the directory which contains fixtures | ||
# You might want to overwrite this method to place your data else where. | ||
# | ||
# @return [String] | ||
# The directory to where your fixtures are stored | ||
def fixtures_directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the finding of the fixture directory can be implemented such that it is only executed once only. I.e. Setting a class variable straight in the class body. And making it configurable like |
||
return @fixtures_directory if @fixtures_directory | ||
|
||
default_path = proc { File.join(root_directory, DEFAULT_FIXTURES_DIRECTORY) } | ||
|
||
candidates = %w( | ||
fixtures | ||
spec/fixtures | ||
features/fixtures | ||
test/fixtures | ||
).map { |dir| File.join(root_directory, dir) } | ||
|
||
@fixtures_directory = candidates.find(default_path) { |dir| File.directory? dir } | ||
end | ||
|
||
# Run a command with aruba | ||
# | ||
# Checks for error during command execution and checks the output to detect | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making aruba root directory configurable is not related to this PR (as I see it). I suggest you take that out in a seperate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but it makes the configuration of the fixtures more cleaner. I added a new PR for this. Would you mind to merge it first, then?