Permalink
Browse files

Hooks accept a tag string but do nothing with it yet.

  • Loading branch information...
1 parent 08718d6 commit 670ce7b860b8690860a76c9a0bdc86f174689285 @richardlawrence committed Jun 25, 2010
@@ -1,6 +1,15 @@
-namespace Cuke4Nuke.Framework
-{
- public class AfterAttribute : HookAttribute
- {
- }
+namespace Cuke4Nuke.Framework
+{
+ public class AfterAttribute : HookAttribute
+ {
+ public AfterAttribute()
+ : base()
+ {
+ }
+
+ public AfterAttribute(string tag)
+ : base(tag)
+ {
+ }
+ }
}
@@ -1,6 +1,15 @@
-namespace Cuke4Nuke.Framework
-{
- public class BeforeAttribute : HookAttribute
- {
- }
-}
+namespace Cuke4Nuke.Framework
+{
+ public class BeforeAttribute : HookAttribute
+ {
+ public BeforeAttribute()
+ : base()
+ {
+ }
+
+ public BeforeAttribute(string tag)
+ : base(tag)
+ {
+ }
+ }
+}
@@ -1,9 +1,16 @@
-using System;
+using System;
+using System.Collections.Generic;
namespace Cuke4Nuke.Framework
{
[AttributeUsage(AttributeTargets.Method)]
public abstract class HookAttribute : Attribute
{
+ public HookAttribute()
+ {
+ }
+
+ public HookAttribute(string tag)
+ {
}
}
View
@@ -73,4 +73,144 @@ Feature: Run .NET Before and After hooks from Cucumber
}
"""
When I run cucumber -f progress features
- Then it should fail
+ Then it should fail
+
+ Scenario: Tagged Before hook (string, positive)
+ Given a file named "features/adding.feature" with:
+ """
+ @my_tag
+ Scenario: Was Before hook called?
+ Then the Before hook should be called
+
+ """
+ And Cuke4Nuke started with a step definition assembly containing:
+ """
+ public class GeneratedSteps
+ {
+ bool _isBeforeCalled = false;
+
+ [Before("@my_tag")]
+ public void Setup()
+ {
+ _isBeforeCalled = true;
+ }
+
+ [Then(@"^the Before hook should be called$")]
+ public void ExpectBeforeHookCalled()
+ {
+ Assert.True(_isBeforeCalled);
+ }
+ }
+ """
+ When I run cucumber -f progress features
+ Then STDERR should be empty
+ And it should pass with
+ """
+ .
+
+ 1 scenario (1 passed)
+ 1 step (1 passed)
+
+ """
+
+ Scenario: Tagged Before hook (string, negative)
+ Given a file named "features/adding.feature" with:
+ """
+ @my_tag
+ Scenario: Was Before hook called?
+ Then the Before hook should not be called
+
+ """
+ And Cuke4Nuke started with a step definition assembly containing:
+ """
+ public class GeneratedSteps
+ {
+ bool _isBeforeCalled = false;
+
+ [Before("@not_my_tag")]
+ public void Setup()
+ {
+ _isBeforeCalled = true;
+ }
+
+ [Then(@"^the Before hook should not be called$")]
+ public void ExpectBeforeHookNotCalled()
+ {
+ Assert.False(_isBeforeCalled);
+ }
+ }
+ """
+ When I run cucumber -f progress features
+ Then STDERR should be empty
+ And it should pass with
+ """
+ .
+
+ 1 scenario (1 passed)
+ 1 step (1 passed)
+
+ """
+
+ Scenario: Tagged After hook (string, positive)
+ Given a file named "features/adding.feature" with:
+ """
+ @my_tag
+ Scenario: After hook defined
+ Given a passing step
+
+ """
+ And Cuke4Nuke started with a step definition assembly containing:
+ """
+ public class GeneratedSteps
+ {
+ [After("@my_tag")]
+ public void TearDown()
+ {
+ throw new Exception();
+ }
+
+ [Given(@"^a passing step$")]
+ public void APassingStep()
+ {
+ }
+ }
+ """
+ When I run cucumber -f progress features
+ Then it should fail
+
+ Scenario: Tagged After hook (string, negative)
+ Given a file named "features/adding.feature" with:
+ """
+ @my_tag
+ Scenario: After hook defined
+ Given a passing step
+
+ """
+ And Cuke4Nuke started with a step definition assembly containing:
+ """
+ public class GeneratedSteps
+ {
+ [After("@not_my_tag")]
+ public void TearDown()
+ {
+ throw new Exception();
+ }
+
+ [Given(@"^a passing step$")]
+ public void APassingStep()
+ {
+ }
+ }
+ """
+ When I run cucumber -f progress features
+ Then STDERR should be empty
+ And it should pass with
+ """
+ .
+
+ 1 scenario (1 passed)
+ 1 step (1 passed)
+
+ """
+
+
@@ -46,13 +46,15 @@ def build_step_definitions(contents)
csc_path = "C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\csc.exe"
assembly_path = File.join(working_dir, 'bin/GeneratedStepDefinitions.dll').gsub('/', '\\')
src_path = File.join(working_dir, 'src/GeneratedStepDefinitions.cs').gsub('/', '\\')
- ref_path = File.expand_path(File.join(examples_dir, '../Cuke4Nuke/Framework/bin/Debug/Cuke4Nuke.Framework.dll')).gsub('/', '\\')
+ cuke4nuke_ref_path = File.expand_path(File.join(examples_dir, '../Cuke4Nuke/Framework/bin/Debug/Cuke4Nuke.Framework.dll')).gsub('/', '\\')
+ nunit_ref_path = File.expand_path(File.join(examples_dir, '../Cuke4Nuke/Specifications/bin/Debug/nunit.framework.dll')).gsub('/', '\\')
template_path = File.expand_path(File.join(File.dirname(__FILE__), 'steps_template.cs.erb'))
generated_code = ERB.new(File.read(template_path)).result(binding)
create_file(assembly_path, '')
create_file(src_path, generated_code)
in_current_dir do
- command = %{#{csc_path} /target:library /out:"#{assembly_path}" /reference:"#{ref_path}" "#{src_path}"}
+ FileUtils.cp nunit_ref_path, File.join(working_dir, 'bin')
+ command = %{#{csc_path} /target:library /out:"#{assembly_path}" /reference:"#{cuke4nuke_ref_path}" /reference:"#{nunit_ref_path}" "#{src_path}"}
run command
raise "Failed to build #{src_path}:\nCMD:#{command}\nEXIT:#{@last_exit_status.to_i}\nSTDERR:\n#{@last_stderr}\nSTDOUT:\n#{@last_stdout}" if @last_exit_status.to_i != 0
end
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using NUnit.Framework;
using Cuke4Nuke.Framework;
namespace Cuke4Nuke.TestStepDefinitions

0 comments on commit 670ce7b

Please sign in to comment.