simple_bdd 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,6 +25,16 @@ The following will call the 'something_happens' method in scope of the current c
25
25
  [Ww]hen "this happens" # calls this_happens
26
26
  [Tt]hen "this change occurs" #calls this_change_occurs
27
27
  [Aa]nd "this other side effect happens" #this_other_side_effect_happens
28
+
29
+ ## RSpec
30
+
31
+ You'll need to require SimpleBDD in the spec helper and include it into your tests like so:
32
+
33
+ require 'simple_bdd'
34
+
35
+ RSpec.configure do |config|
36
+ config.include SimpleBdd
37
+ end
28
38
 
29
39
  ## Contributing
30
40
 
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
+ task :bundle_install do
2
+ system("bundle")
3
+ end
4
+
1
5
  require "bundler/gem_tasks"
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => [:bundle_install, :spec]
@@ -1,3 +1,3 @@
1
1
  module SimpleBdd
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/simple_bdd.rb CHANGED
@@ -1,12 +1,37 @@
1
1
  require "simple_bdd/version"
2
2
 
3
3
  module SimpleBdd
4
-
5
- ["given", "when", "then", "and", "Given", "When", "Then", "And"].each do |method|
6
- define_method(method) do |message|
7
- method = message.downcase.gsub(" ", "_").gsub(/\W/, "")
8
- send(method)
4
+ %w[Given When Then And Also].each do |method|
5
+ define_method(method) do |message|
6
+ begin
7
+ send methodize(message)
8
+ rescue NoMethodError => error
9
+ message_does_not_exist(
10
+ methodize(message), error
11
+ )
12
+ end
9
13
  end
14
+
15
+ alias_method method.downcase, method
16
+ end
17
+
18
+ PRESERVED_CHARS = '\\w'
19
+ CONVERTED_CHARS = Regexp.escape(' /')
20
+
21
+ def methodize(message)
22
+ message
23
+ .downcase
24
+ .gsub(/[^#{PRESERVED_CHARS}#{CONVERTED_CHARS}]/, "")
25
+ .gsub(/[#{CONVERTED_CHARS}]+/, "_")
10
26
  end
11
27
 
28
+ if defined?(::RSpec)
29
+ def message_does_not_exist(message, error)
30
+ pending(message)
31
+ end
32
+ else
33
+ def message_does_not_exist(message, error)
34
+ raise error
35
+ end
36
+ end
12
37
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Pending features in rspec" do
4
+ it "should make the step pending" do
5
+ self.should_receive(:pending).with("i_have_not_defined_a_step")
6
+ Given "I have not defined a step"
7
+ end
8
+ end
@@ -5,15 +5,33 @@ class SimpleBddExample
5
5
  end
6
6
 
7
7
  describe SimpleBddExample do
8
-
9
8
  let(:subject) { SimpleBddExample.new }
10
9
 
11
- describe "#given, #when, #then, #and" do
12
- ["given", "when", "then", "and", "Given", "When", "Then", "And"].each do |method|
10
+ describe "#given, #when, #then, #and, #also" do
11
+ ["given", "when", "then", "and", "Given", "When", "Then", "And", "Also", "also"].each do |method|
13
12
  it "calls the method after translating the string" do
14
- subject.should_receive(:something_something_darkside)
15
- subject.send(method, "Something, Something Darkside")
13
+ subject.should_receive(:something)
14
+ subject.send(method, "something")
16
15
  end
17
16
  end
18
17
  end
18
+
19
+ describe "#methodize" do
20
+ it "removes special chars" do
21
+ subject.send(:methodize, "bond, james bond").should == "bond_james_bond"
22
+ end
23
+
24
+ it "converts to lower case" do
25
+ subject.send(:methodize, "HELLO WORLD").should == "hello_world"
26
+ end
27
+
28
+ it "compacts adjacent separators" do
29
+ subject.send(:methodize, "Bates & Lolcat Realty").should == "bates_lolcat_realty"
30
+ subject.send(:methodize, "Ruby / Python / Scala, same deal").should == "ruby_python_scala_same_deal"
31
+ end
32
+
33
+ it "underscores slashes" do
34
+ subject.send(:methodize, "Chocolate/Vanilla Cake").should == "chocolate_vanilla_cake"
35
+ end
36
+ end
19
37
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,10 @@ RSpec.configure do |config|
3
3
  config.run_all_when_everything_filtered = true
4
4
  config.filter_run :focus
5
5
  config.order = 'random'
6
-
6
+
7
7
  require File.dirname(__FILE__) + '/../lib/simple_bdd'
8
+
9
+ RSpec.configure do |config|
10
+ config.include SimpleBdd
11
+ end
8
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_bdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
12
+ date: 2013-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -75,6 +75,7 @@ files:
75
75
  - lib/simple_bdd.rb
76
76
  - lib/simple_bdd/version.rb
77
77
  - simple_bdd.gemspec
78
+ - spec/pending_feature_spec.rb
78
79
  - spec/simple_bdd_spec.rb
79
80
  - spec/spec_helper.rb
80
81
  homepage: ''
@@ -89,24 +90,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
90
  - - ! '>='
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
- segments:
93
- - 0
94
- hash: -1526797260797757725
95
93
  required_rubygems_version: !ruby/object:Gem::Requirement
96
94
  none: false
97
95
  requirements:
98
96
  - - ! '>='
99
97
  - !ruby/object:Gem::Version
100
98
  version: '0'
101
- segments:
102
- - 0
103
- hash: -1526797260797757725
104
99
  requirements: []
105
100
  rubyforge_project:
106
- rubygems_version: 1.8.24
101
+ rubygems_version: 1.8.25
107
102
  signing_key:
108
103
  specification_version: 3
109
104
  summary: Gherkin methods that turn strings into methods
110
105
  test_files:
106
+ - spec/pending_feature_spec.rb
111
107
  - spec/simple_bdd_spec.rb
112
108
  - spec/spec_helper.rb