Skip to content

Commit

Permalink
Hooks accept a tag string but do nothing with it yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlawrence committed Jun 25, 2010
1 parent 08718d6 commit 670ce7b
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 15 deletions.
19 changes: 14 additions & 5 deletions Cuke4Nuke/Framework/AfterAttribute.cs
@@ -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)
{
}
}
}
21 changes: 15 additions & 6 deletions Cuke4Nuke/Framework/BeforeAttribute.cs
@@ -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)
{
}
}
}
9 changes: 8 additions & 1 deletion Cuke4Nuke/Framework/HookAttribute.cs
@@ -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)
{
}
}
}
Expand Down
142 changes: 141 additions & 1 deletion features/hooks.feature
Expand Up @@ -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)
"""


6 changes: 4 additions & 2 deletions features/support/env.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions features/support/steps_template.cs.erb
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Cuke4Nuke.Framework;

namespace Cuke4Nuke.TestStepDefinitions
Expand Down

0 comments on commit 670ce7b

Please sign in to comment.