Skip to content

Commit

Permalink
Improve flexibility of geordi test #216
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosedler committed Jun 14, 2024
1 parent caf6ecc commit 02a5a98
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 7 deletions.
26 changes: 25 additions & 1 deletion features/tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ Feature: The tests command
And the output from "geordi tests features" should contain "> Only: features"


Scenario: Run certain specs and features together
Given an empty file named "spec/spec_helper.rb"
And an empty file named "spec/some_spec.rb"
And an empty file named "features/some.feature"

When I run `geordi tests spec/some_spec.rb features/some.feature`
Then the output should contain "# Running specs"
And the output should contain "Only: spec/some_spec.rb"
And the output should contain "> Only: features/some.feature"


Scenario: Run spec and features in directories
Given an empty file named "spec/spec_helper.rb"
And an empty file named "spec/some_spec.rb"
And an empty file named "features/some.feature"

When I run `geordi tests features spec`
Then the output should contain "# Running specs"
Then the output should contain "# Running features"


Scenario: Geordi's options are processed
Given an empty file named "features/some.feature"

Expand All @@ -52,6 +73,9 @@ Feature: The tests command

Scenario: Unknown options are passed through
Given an empty file named "spec/spec_helper.rb"
And an empty file named "features/some.feature"

When I run `geordi tests spec/ --some-option`
When I run `geordi tests spec/ features/ --some-option`
Then the output should contain "Util.run! bundle exec rspec spec/ --some-option"
And the output should contain "Features failed"
And the output should contain "invalid option: --some-option"
11 changes: 5 additions & 6 deletions lib/geordi/commands/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ def tests(*args)

if args.empty?
Interaction.fail error_message
elsif args.first.start_with? 'spec'
invoke 'rspec', args, opts
elsif args.first.start_with? 'features'
invoke 'cucumber', args, opts
else
Interaction.fail error_message
end
rspec_paths = args.select { |a| Util.rspec_path?(a) }
cucumber_paths = args.select { |a| Util.cucumber_path?(a) }

invoke('rspec', rspec_paths, opts) if rspec_paths.any?
invoke('cucumber', cucumber_paths, opts) if cucumber_paths.any?
end
else
rake_result = invoke_geordi 'with_rake'

Expand Down
8 changes: 8 additions & 0 deletions lib/geordi/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ def ruby_version
version_string = testing? ? ENV['GEORDI_TESTING_RUBY_VERSION'] : RUBY_VERSION
Gem::Version.new(version_string)
end

def cucumber_path?(path)
%r{(^|\/)features|\.feature($|:)}.match?(path)
end

def rspec_path?(path)
%r{(^|\/)spec|_spec\.rb($|:)}.match?(path)
end
end
end
end
60 changes: 60 additions & 0 deletions spec/util_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
RSpec.describe Geordi::Util do
describe '.rspec_path?' do
it 'returns true if given a spec path or spec filename' do
%w[
spec
spec/
foo_spec.rb
foo_spec.rb:123
tests/foo_spec.rb
].each do |path|
expect(described_class.rspec_path?(path)).to be true
end
end


it 'returns false if given argument is not a spec path or filename' do
%w[
rspec
foo.rb
tests/foo.rb
foo_spec_test.rb
foo.feature
features/foo.feature
].each do |path|
expect(described_class.rspec_path?(path)).to be false
end
end

end

describe '.cucumber_path?' do
it 'returns true if given a cucumber path or cucumber filename' do
%w[
features
features/
foo.feature
foo.feature:123
tests/foo.feature:234
].each do |path|
expect(described_class.cucumber_path?(path)).to be true
end
end


it 'returns false if given argument is not a cucumber path or filename' do
%w[
cucumber
foo.rb
tests/foo.rb
foo_feature.rb
foo_spec.rb
spec
spec/foo_spec.rb
].each do |path|
expect(described_class.cucumber_path?(path)).to be false
end
end

end
end

0 comments on commit 02a5a98

Please sign in to comment.