Skip to content

Commit

Permalink
Merge pull request #12 from frodsan/scope_name
Browse files Browse the repository at this point in the history
Run tests by scope name
  • Loading branch information
Damian Janowski committed May 29, 2014
2 parents 2e2941e + 55ead68 commit d049406
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/cutest
Expand Up @@ -11,6 +11,7 @@ require_relative "../lib/cutest/vendor/clap"
files = Clap.run ARGV,
"-r" => lambda { |file| require file },
"-o" => lambda { |name| cutest[:only] = name },
"-s" => lambda { |name| cutest[:scope] = name },
"-v" => lambda { puts Cutest::VERSION }

if files.any?
Expand Down
6 changes: 4 additions & 2 deletions lib/cutest.rb
Expand Up @@ -94,8 +94,10 @@ def cutest

# Create a class where the block will be evaluated. Recommended to improve
# isolation between tests.
def scope(&block)
Cutest::Scope.new(&block).call
def scope(name = nil, &block)
if !cutest[:scope] || cutest[:scope] == name
Cutest::Scope.new(&block).call
end
end

# Prepare the environment in order to run the tests. This method can be
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/only_run_given_scope_name.rb
@@ -0,0 +1,15 @@
scope "another scope" do
test do
raise "This is not raised"
end
end

scope "scope" do
test "test" do
assert true
end

test do
raise "This is raised"
end
end
12 changes: 12 additions & 0 deletions test/run.rb
Expand Up @@ -76,3 +76,15 @@

assert_equal(expected, out)
end

test "only runs given scope name" do
out = %x{./bin/cutest test/fixtures/only_run_given_scope_name.rb -s scope}

assert out =~ /This is raised/
end

test "runs by given scope and test names" do
%x{./bin/cutest test/fixtures/only_run_given_scope_name.rb -s scope -o test}

assert_equal 0, $?.to_i
end

0 comments on commit d049406

Please sign in to comment.