rspec-parameterized 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module Parameterized
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -27,7 +27,7 @@ module RSpec
27
27
  #
28
28
  # ## Example
29
29
  #
30
- # where(:a, :b, :answer) do
30
+ # where_table(:a, :b, :answer) do
31
31
  # 1 | 2 | 3
32
32
  # 5 | 8 | 13
33
33
  # 0 | 0 | 0
@@ -59,7 +59,13 @@ module RSpec
59
59
  private
60
60
  def set_parameters(arg_names, param_sets)
61
61
  @arg_names = arg_names
62
- @param_sets = param_sets
62
+
63
+ @param_sets = if arg_names.count == 1 && !param_sets[0].is_a?(Array)
64
+ param_sets.map { |x| Array[x] }
65
+ else
66
+ param_sets
67
+ end
68
+
63
69
  if @parameterized_pending_cases
64
70
  @parameterized_pending_cases.each { |e|
65
71
  define_cases(arg_names, param_sets, *e[0], &e[1])
@@ -70,7 +76,12 @@ module RSpec
70
76
  def separate_table_like_block(b)
71
77
  sexp = b.to_sexp(:strip_enclosure => true)
72
78
 
73
- lines = sexp.find_nodes(:call)
79
+ if sexp.sexp_type == :block
80
+ lines = sexp.find_nodes(:call)
81
+ else
82
+ lines = [sexp]
83
+ end
84
+
74
85
  lines.map do |l|
75
86
  rev_insts = []
76
87
  while l.sexp_type == :call and l[2] == :|
@@ -92,8 +103,10 @@ module RSpec
92
103
 
93
104
  def define_cases(arg_names, param_sets, *args, &block)
94
105
  param_sets.each do |params|
95
- describe(params.inspect, *args) do
96
- [arg_names, params].transpose.each do |n|
106
+ pairs = [arg_names, params].transpose
107
+ pretty_params = pairs.map {|t| "#{t[0]}: #{params_inspect(t[1])}"}.join(", ")
108
+ describe(pretty_params, *args) do
109
+ pairs.each do |n|
97
110
  let(n[0]) { n[1] }
98
111
  end
99
112
 
@@ -101,6 +114,14 @@ module RSpec
101
114
  end
102
115
  end
103
116
  end
117
+
118
+ def params_inspect(obj)
119
+ begin
120
+ obj.is_a?(Proc) ? obj.to_raw_source : obj.inspect
121
+ rescue Sourcify::NoMatchingProcError
122
+ return obj.inspect
123
+ end
124
+ end
104
125
  end
105
126
  end
106
127
 
@@ -33,6 +33,24 @@ describe RSpec::Parameterized do
33
33
  end
34
34
  end
35
35
 
36
+ describe "lambda parameter" do
37
+ where(:a, :b, :answer) do
38
+ [
39
+ [1 , 2 , -> {should == 3}],
40
+ [5 , 8 , -> {should == 13}],
41
+ [0 , 0 , -> {should == 0}]
42
+ ]
43
+ end
44
+
45
+ with_them do
46
+ subject {a + b}
47
+ it "should do additions" do
48
+ self.instance_exec(&answer)
49
+ end
50
+ end
51
+ end
52
+
53
+
36
54
  describe "table separated with pipe" do
37
55
  where_table(:a, :b, :answer) do
38
56
  1 | 2 | 3
@@ -88,4 +106,28 @@ describe RSpec::Parameterized do
88
106
  it { should be_is_a Numeric }
89
107
  end
90
108
  end
109
+
110
+ context "when the where has only one parameter to be set" do
111
+ where(:x) do
112
+ [1, 2, 3]
113
+ end
114
+
115
+ with_them do
116
+ it 'can take an array of elements' do
117
+ x.should == x
118
+ end
119
+ end
120
+ end
121
+
122
+ context "when the table has only a row" do
123
+ where_table(:a, :b, :answer) do
124
+ 1 | 2 | 3
125
+ end
126
+
127
+ with_them do
128
+ it "a plus b is answer" do
129
+ (a + b).should == answer
130
+ end
131
+ end
132
+ end
91
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-parameterized
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: 2012-05-22 00:00:00.000000000 Z
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: -875834415
111
+ hash: -139463347
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  segments:
119
119
  - 0
120
- hash: -875834415
120
+ hash: -139463347
121
121
  requirements: []
122
122
  rubyforge_project:
123
123
  rubygems_version: 1.8.24