pickle 0.4.11 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,9 +7,9 @@ describe Pickle::Parser::Matchers do
7
7
  def config
8
8
  @config ||= Pickle::Config.new do |c|
9
9
  c.factories = {
10
- 'user' => mock('factory'),
11
- 'car' => mock('factory'),
12
- 'fast_car' => mock('factory')
10
+ 'user' => double('factory'),
11
+ 'car' => double('factory'),
12
+ 'fast_car' => double('factory')
13
13
  }
14
14
  c.predicates = %w(name status fancy? super_fancy? has_style? has_super_style?)
15
15
  end
@@ -19,7 +19,7 @@ describe Pickle::Parser::Matchers do
19
19
  def self.atom_should_match(atom, strings)
20
20
  Array(strings).each do |string|
21
21
  it "#{atom} should match '#{string}'" do
22
- string.should match(/^#{send atom}$/)
22
+ expect(string).to match(/^#{send atom}$/)
23
23
  end
24
24
  end
25
25
  end
@@ -27,7 +27,7 @@ describe Pickle::Parser::Matchers do
27
27
  def self.atom_should_not_match(atom, strings)
28
28
  Array(strings).each do |string|
29
29
  it "#{atom} should NOT match '#{string}'" do
30
- string.should_not match(/^#{send atom}$/)
30
+ expect(string).not_to match(/^#{send atom}$/)
31
31
  end
32
32
  end
33
33
  end
@@ -63,8 +63,8 @@ describe Pickle::Parser::Matchers do
63
63
 
64
64
  describe "capture methods" do
65
65
  it "capture_field should == '(' + match_field + ')'" do
66
- should_receive(:match_field).and_return('MATCH_FIELD')
67
- capture_field.should == '(MATCH_FIELD)'
66
+ expect(self).to receive(:match_field).and_return('MATCH_FIELD')
67
+ expect(capture_field).to eq('(MATCH_FIELD)')
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -6,12 +6,12 @@ describe Pickle::Parser do
6
6
  end
7
7
 
8
8
  it "should raise error when created with no config" do
9
- lambda{ Pickle::Parser.new }.should raise_error(ArgumentError)
9
+ expect{ Pickle::Parser.new }.to raise_error(ArgumentError)
10
10
  end
11
11
 
12
12
  describe "when a 'user' factory exists in config" do
13
13
  before do
14
- @parser.config.stub(:factories).and_return('user' => mock('User'))
14
+ allow(@parser.config).to receive(:factories).and_return('user' => double('User'))
15
15
  end
16
16
 
17
17
  describe 'misc regexps' do
@@ -21,116 +21,116 @@ describe Pickle::Parser do
21
21
  end
22
22
 
23
23
  it "should match 'a user exists'" do
24
- 'a user exists'.should match(@regexp)
24
+ expect('a user exists').to match(@regexp)
25
25
  end
26
26
 
27
27
  it "should caputure 'a user' from 'a user exists'" do
28
- 'a user exists'.match(@regexp)[1].should == 'a user'
28
+ expect('a user exists'.match(@regexp)[1]).to eq('a user')
29
29
  end
30
30
  end
31
31
  end
32
32
 
33
33
  describe '#parse_field' do
34
34
  it "should return {'a' => 'b'} for 'a: \"b\"'" do
35
- @parser.parse_field('a: "b"').should == {'a' => 'b'}
35
+ expect(@parser.parse_field('a: "b"')).to eq({'a' => 'b'})
36
36
  end
37
37
 
38
38
  it "should raise error for invalid field 'a : b'" do
39
- lambda { @parser.parse_field('a : b') }.should raise_error(ArgumentError)
39
+ expect { @parser.parse_field('a : b') }.to raise_error(ArgumentError)
40
40
  end
41
41
  end
42
42
 
43
43
  describe '#parse_fields' do
44
44
  it 'should return {} for blank argument' do
45
- @parser.parse_fields(nil).should == {}
46
- @parser.parse_fields('').should == {}
45
+ expect(@parser.parse_fields(nil)).to eq({})
46
+ expect(@parser.parse_fields('')).to eq({})
47
47
  end
48
48
 
49
49
  it 'should raise error for invalid argument' do
50
- lambda { @parser.parse_fields('foo foo') }.should raise_error(ArgumentError)
50
+ expect { @parser.parse_fields('foo foo') }.to raise_error(ArgumentError)
51
51
  end
52
52
 
53
53
  it '(\'foo: "bar"\') should == { "foo" => "bar"}' do
54
- @parser.parse_fields('foo: "bar"').should == { "foo" => "bar"}
54
+ expect(@parser.parse_fields('foo: "bar"')).to eq({ "foo" => "bar"})
55
55
  end
56
56
 
57
57
  it '(\'foo: "something \"quoted\""\') should == { "foo" => "bar"}' do
58
- @parser.parse_fields('foo: "something \"quoted\""').should == { "foo" => 'something "quoted"' }
58
+ expect(@parser.parse_fields('foo: "something \"quoted\""')).to eq({ "foo" => 'something "quoted"' })
59
59
  end
60
60
 
61
61
  it '("bool: true") should == { "bool" => true}' do
62
- @parser.parse_fields('bool: true').should == {"bool" => true}
62
+ expect(@parser.parse_fields('bool: true')).to eq({"bool" => true})
63
63
  end
64
64
 
65
65
  it '("bool: false") should == { "bool" => false}' do
66
- @parser.parse_fields('bool: false').should == {"bool" => false}
66
+ expect(@parser.parse_fields('bool: false')).to eq({"bool" => false})
67
67
  end
68
68
 
69
69
  it '("int: 10") should == { "int" => 10 }' do
70
- @parser.parse_fields('int: 10').should == {"int" => 10}
70
+ expect(@parser.parse_fields('int: 10')).to eq({"int" => 10})
71
71
  end
72
72
 
73
73
  it '("float: 10.1") should == { "float" => 10.1 }' do
74
- @parser.parse_fields('float: 10.1').should == {"float" => 10.1}
74
+ expect(@parser.parse_fields('float: 10.1')).to eq({"float" => 10.1})
75
75
  end
76
76
 
77
77
  it '(\'foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123\') should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}' do
78
- @parser.parse_fields('foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123').should == {"foo" => "bar", "bar_man" => "wonga wonga", "baz_woman" => "one \"two\" three", "gump" => 123}
78
+ expect(@parser.parse_fields('foo: "bar", bar_man: "wonga wonga", baz_woman: "one \"two\" three", gump: 123')).to eq({"foo" => "bar", "bar_man" => "wonga wonga", "baz_woman" => "one \"two\" three", "gump" => 123})
79
79
  end
80
80
  end
81
81
 
82
82
  describe '#parse_model' do
83
83
  it '("a user") should == ["user", ""]' do
84
- @parser.parse_model("a user").should == ["user", ""]
84
+ expect(@parser.parse_model("a user")).to eq(["user", ""])
85
85
  end
86
86
 
87
87
  it '("the user") should == ["user", ""]' do
88
- @parser.parse_model("the user").should == ["user", ""]
88
+ expect(@parser.parse_model("the user")).to eq(["user", ""])
89
89
  end
90
90
 
91
91
  it '("1 user") should == ["user", ""]' do
92
- @parser.parse_model("1 user").should == ["user", ""]
92
+ expect(@parser.parse_model("1 user")).to eq(["user", ""])
93
93
  end
94
94
 
95
95
  it '(\'an user: "jim jones"\') should == ["user", "jim_jones"]' do
96
- @parser.parse_model('an user: "jim jones"').should == ["user", "jim_jones"]
96
+ expect(@parser.parse_model('an user: "jim jones"')).to eq(["user", "jim_jones"])
97
97
  end
98
98
 
99
99
  it '(\'that user: "herbie"\') should == ["user", "herbie"]' do
100
- @parser.parse_model('that user: "herbie"').should == ["user", "herbie"]
100
+ expect(@parser.parse_model('that user: "herbie"')).to eq(["user", "herbie"])
101
101
  end
102
102
 
103
103
  it '(\'the 12th user\') should == ["user", 11]' do
104
- @parser.parse_model('the 12th user').should == ["user", 11]
104
+ expect(@parser.parse_model('the 12th user')).to eq(["user", 11])
105
105
  end
106
106
 
107
107
  it '(\'the last user\') should == ["user", -1]' do
108
- @parser.parse_model('the last user').should == ["user", -1]
108
+ expect(@parser.parse_model('the last user')).to eq(["user", -1])
109
109
  end
110
110
 
111
111
  it '("the first user") should == ["user", 0]' do
112
- @parser.parse_model('the first user').should == ["user", 0]
112
+ expect(@parser.parse_model('the first user')).to eq(["user", 0])
113
113
  end
114
114
 
115
115
  it '("the 1st user") should == ["user", 0]' do
116
- @parser.parse_model('the 1st user').should == ["user", 0]
116
+ expect(@parser.parse_model('the 1st user')).to eq(["user", 0])
117
117
  end
118
118
  end
119
119
 
120
120
  describe "#parse_index" do
121
121
  it '("1st") should == 0' do
122
- @parser.parse_index("1st").should == 0
122
+ expect(@parser.parse_index("1st")).to eq(0)
123
123
  end
124
124
 
125
125
  it '("24th") should == 23' do
126
- @parser.parse_index("24th").should == 23
126
+ expect(@parser.parse_index("24th")).to eq(23)
127
127
  end
128
128
  it '("first") should == 0' do
129
- @parser.parse_index("first").should == 0
129
+ expect(@parser.parse_index("first")).to eq(0)
130
130
  end
131
131
 
132
132
  it '("last") should == -1' do
133
- @parser.parse_index("last").should == -1
133
+ expect(@parser.parse_index("last")).to eq(-1)
134
134
  end
135
135
  end
136
136
  end
@@ -142,23 +142,23 @@ describe Pickle::Parser do
142
142
  c.map 'I', 'myself', :to => 'user: "me"'
143
143
  end
144
144
  @parser = Pickle::Parser.new(:config => @config)
145
- @parser.config.stub(:factories).and_return('user' => mock('User'))
145
+ allow(@parser.config).to receive(:factories).and_return('user' => double('User'))
146
146
  end
147
147
 
148
148
  it "'I' should match /\#{match_model}/" do
149
- 'I'.should match(/#{@parser.match_model}/)
149
+ expect('I').to match(/#{@parser.match_model}/)
150
150
  end
151
151
 
152
152
  it "'myself' should match /\#{match_model}/" do
153
- 'myself'.should match(/#{@parser.match_model}/)
153
+ expect('myself').to match(/#{@parser.match_model}/)
154
154
  end
155
155
 
156
156
  it "parse_model('I') should == ['user', 'me']" do
157
- @parser.parse_model('I').should == ["user", "me"]
157
+ expect(@parser.parse_model('I')).to eq(["user", "me"])
158
158
  end
159
159
 
160
160
  it "parse_model('myself') should == ['user', 'me']" do
161
- @parser.parse_model('myself').should == ["user", "me"]
161
+ expect(@parser.parse_model('myself')).to eq(["user", "me"])
162
162
  end
163
163
  end
164
164
  end
@@ -7,10 +7,10 @@ describe Pickle::Path do
7
7
 
8
8
  describe "#path_to_pickle, when the model doesn't exist" do
9
9
  before do
10
- stub!(:model).and_return(nil)
10
+ allow(self).to receive(:model).and_return(nil)
11
11
  end
12
12
  it "('that user', :extra => 'new comment') should raise the error raised by model!" do
13
- lambda { path_to_pickle "that user", "new comment" }.should raise_error(RuntimeError, 'Could not figure out a path for ["that user", "new comment"] {}')
13
+ expect { path_to_pickle "that user", "new comment" }.to raise_error(RuntimeError, 'Could not figure out a path for ["that user", "new comment"] {}')
14
14
  end
15
15
 
16
16
  end
@@ -18,82 +18,82 @@ describe Pickle::Path do
18
18
  describe "#path_to_pickle" do
19
19
  describe "when model returns a user" do
20
20
  let :user_class do
21
- mock 'User', :name => 'User'
21
+ double 'User', :name => 'User'
22
22
  end
23
23
 
24
24
  let :user do
25
- mock 'user', :class => user_class
25
+ double 'user', :class => user_class
26
26
  end
27
27
 
28
28
  before do
29
- stub!(:model).and_return(user)
29
+ allow(self).to receive(:model).and_return(user)
30
30
  end
31
31
 
32
32
  it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
33
- should_receive(:model).with('a user')
34
- should_receive(:model).with('the user: "fred"')
35
- stub!(:user_user_path).and_return('the path')
36
- path_to_pickle('a user', 'the user: "fred"').should == 'the path'
33
+ expect(self).to receive(:model).with('a user')
34
+ expect(self).to receive(:model).with('the user: "fred"')
35
+ allow(self).to receive(:user_user_path).and_return('the path')
36
+ expect(path_to_pickle('a user', 'the user: "fred"')).to eq('the path')
37
37
  end
38
38
 
39
39
  it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
40
- should_receive(:foo_user_path).with(user).and_return('the path')
41
- path_to_pickle('a user', :action => 'foo').should == 'the path'
40
+ expect(self).to receive(:foo_user_path).with(user).and_return('the path')
41
+ expect(path_to_pickle('a user', :action => 'foo')).to eq('the path')
42
42
  end
43
43
 
44
44
  it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
45
- should_receive(:foo_user_path).with(user).and_raise(NoMethodError)
46
- lambda { path_to_pickle('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
45
+ expect(self).to receive(:foo_user_path).with(user).and_raise(NoMethodError)
46
+ expect { path_to_pickle('a user', :action => 'foo') }.to raise_error(Exception, /Could not figure out a path for/)
47
47
  end
48
48
 
49
49
  it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
50
- should_receive(:user_foo_path).with(user).and_return('the path')
51
- path_to_pickle('a user', :segment => 'foo').should == 'the path'
50
+ expect(self).to receive(:user_foo_path).with(user).and_return('the path')
51
+ expect(path_to_pickle('a user', :segment => 'foo')).to eq('the path')
52
52
  end
53
53
 
54
54
  it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
55
- should_receive(:user_foo_path).with(user).and_raise(NoMethodError)
56
- lambda { path_to_pickle('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
55
+ expect(self).to receive(:user_foo_path).with(user).and_raise(NoMethodError)
56
+ expect { path_to_pickle('a user', :segment => 'foo') }.to raise_error(Exception, /Could not figure out a path for/)
57
57
  end
58
58
 
59
59
  it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
60
- should_receive(:new_user_comment_path).with(user).and_return('the path')
61
- path_to_pickle('a user', :segment => 'comment', :action => 'new').should == 'the path'
60
+ expect(self).to receive(:new_user_comment_path).with(user).and_return('the path')
61
+ expect(path_to_pickle('a user', :segment => 'comment', :action => 'new')).to eq('the path')
62
62
  end
63
63
 
64
64
  it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
65
- should_receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
66
- lambda { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
65
+ expect(self).to receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
66
+ expect { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.to raise_error(Exception, /Could not figure out a path for/)
67
67
  end
68
68
 
69
69
  it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
70
- should_receive(:new_user_comment_path).with(user).and_return('the path')
71
- path_to_pickle('a user', :extra => 'new comment').should == 'the path'
70
+ expect(self).to receive(:new_user_comment_path).with(user).and_return('the path')
71
+ expect(path_to_pickle('a user', :extra => 'new comment')).to eq('the path')
72
72
  end
73
73
 
74
74
  it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
75
- should_receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
76
- lambda { path_to_pickle('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
75
+ expect(self).to receive(:new_user_comment_path).with(user).and_raise(NoMethodError)
76
+ expect { path_to_pickle('a user', :extra => 'new comment') }.to raise_error(Exception, /Could not figure out a path for/)
77
77
  end
78
78
 
79
79
  describe "when args is a list of pickle and non pickle models" do
80
80
  before do
81
- stub!(:model).with("account").and_return(nil)
81
+ allow(self).to receive(:model).with("account").and_return(nil)
82
82
  end
83
83
 
84
84
  it "('account', 'the user') should return account_user_path(<user>)" do
85
- should_receive(:account_user_path).with(user).and_return("the path")
86
- path_to_pickle('account', 'the user').should == 'the path'
85
+ expect(self).to receive(:account_user_path).with(user).and_return("the path")
86
+ expect(path_to_pickle('account', 'the user')).to eq('the path')
87
87
  end
88
88
  end
89
89
 
90
90
  describe "(private API)" do
91
91
  it "('a user', :extra => 'new ish comment') should try combinations of 'new', 'ish', 'comment'" do
92
- should_receive(:pickle_path_for_resources_action_segment).with([user], '', 'new_ish_comment').once
93
- should_receive(:pickle_path_for_resources_action_segment).with([user], 'new', 'ish_comment').once
94
- should_receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish', 'comment').once
95
- should_receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish_comment', '').once
96
- lambda { path_to_pickle('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
92
+ expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], '', 'new_ish_comment').once
93
+ expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], 'new', 'ish_comment').once
94
+ expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish', 'comment').once
95
+ expect(self).to receive(:pickle_path_for_resources_action_segment).with([user], 'new_ish_comment', '').once
96
+ expect { path_to_pickle('a user', :extra => 'new ish comment') }.to raise_error(Exception, /Could not figure out a path for/)
97
97
  end
98
98
  end
99
99
  end
@@ -15,11 +15,11 @@ describe Pickle::Session do
15
15
  include Pickle::Session
16
16
 
17
17
  let :user_class do
18
- mock("User class", :name => 'User')
18
+ double("User class", :name => 'User')
19
19
  end
20
20
 
21
21
  let :user do
22
- mock("user", :class => user_class, :id => 1)
22
+ double("user", :class => user_class, :id => 100)
23
23
  end
24
24
 
25
25
  let :user_factory do
@@ -27,17 +27,17 @@ describe Pickle::Session do
27
27
  end
28
28
 
29
29
  before do
30
- config.stub(:factories).and_return('user' => user_factory)
30
+ allow(config).to receive(:factories).and_return('user' => user_factory)
31
31
  end
32
32
 
33
33
  shared_examples_for "Pickle::Session proxy missing methods to parser" do
34
34
  it "should forward to pickle_parser it responds_to them" do
35
- subject.pickle_parser.should_receive(:parse_model)
35
+ expect(subject.pickle_parser).to receive(:parse_model)
36
36
  subject.parse_model
37
37
  end
38
38
 
39
39
  it "should raise error if pickle_parser don't know about em" do
40
- lambda { subject.parse_infinity }.should raise_error
40
+ expect { subject.parse_infinity }.to raise_error
41
41
  end
42
42
  end
43
43
 
@@ -59,51 +59,51 @@ describe Pickle::Session do
59
59
 
60
60
  shared_examples_for "after storing a single user" do
61
61
  it "created_models('user') should be array containing the original user" do
62
- created_models('user').should == [user]
62
+ expect(created_models('user')).to eq([user])
63
63
  end
64
64
 
65
65
  describe "the original user should be retrievable with" do
66
66
  it "created_model('the user')" do
67
- created_model('the user').should == user
67
+ expect(created_model('the user')).to eq(user)
68
68
  end
69
69
 
70
70
  it "created_model('1st user')" do
71
- created_model('1st user').should == user
71
+ expect(created_model('1st user')).to eq(user)
72
72
  end
73
73
 
74
74
  it "created_model('last user')" do
75
- created_model('last user').should == user
75
+ expect(created_model('last user')).to eq(user)
76
76
  end
77
77
  end
78
78
 
79
79
  describe "(found from db)" do
80
80
  let :user_from_db do
81
- user.dup.tap {|from_db| from_db.stub!(:id).and_return(100) }
81
+ user.dup.tap {|from_db| allow(from_db).to receive(:id).and_return(100) }
82
82
  end
83
83
 
84
84
  before do
85
- Pickle::Adapter.stub!(:get_model).with(user_class, 100).and_return(user_from_db)
85
+ allow(Pickle::Adapter).to receive(:get_model).with(user_class, 100).and_return(user_from_db)
86
86
  end
87
87
 
88
88
  it "models('user') should be array containing user" do
89
- models('user').should == [user_from_db]
89
+ expect(models('user')).to eq([user_from_db])
90
90
  end
91
91
 
92
92
  describe "user should be retrievable with" do
93
93
  it "model('the user')" do
94
- model('the user').should == user_from_db
94
+ expect(model('the user')).to eq(user_from_db)
95
95
  end
96
96
 
97
97
  it "model('1st user')" do
98
- model('1st user').should == user_from_db
98
+ expect(model('1st user')).to eq(user_from_db)
99
99
  end
100
100
 
101
101
  it "model('last user')" do
102
- model('last user').should == user_from_db
102
+ expect(model('last user')).to eq(user_from_db)
103
103
  end
104
104
 
105
105
  it "model!('last user')" do
106
- model('last user').should == user_from_db
106
+ expect(model('last user')).to eq(user_from_db)
107
107
  end
108
108
  end
109
109
  end
@@ -111,12 +111,12 @@ describe Pickle::Session do
111
111
 
112
112
  describe "#create_model" do
113
113
  before do
114
- user_factory.stub!(:create).and_return(user)
114
+ allow(user_factory).to receive(:create).and_return(user)
115
115
  end
116
116
 
117
117
  describe "('a user')" do
118
118
  it "should call user_factory.create({})" do
119
- user_factory.should_receive(:create).with({})
119
+ expect(user_factory).to receive(:create).with({})
120
120
  create_model('a user')
121
121
  end
122
122
 
@@ -129,7 +129,7 @@ describe Pickle::Session do
129
129
 
130
130
  describe "('1 user', 'foo: \"bar\", baz: \"bing bong\"')" do
131
131
  it "should call user_factory.create({'foo' => 'bar', 'baz' => 'bing bong'})" do
132
- user_factory.should_receive(:create).with({'foo' => 'bar', 'baz' => 'bing bong'})
132
+ expect(user_factory).to receive(:create).with({'foo' => 'bar', 'baz' => 'bing bong'})
133
133
  create_model('1 user', 'foo: "bar", baz: "bing bong"')
134
134
  end
135
135
 
@@ -142,7 +142,7 @@ describe Pickle::Session do
142
142
 
143
143
  describe "('an user: \"fred\")" do
144
144
  it "should call user_factory.create({})" do
145
- user_factory.should_receive(:create).with({})
145
+ expect(user_factory).to receive(:create).with({})
146
146
  create_model('an user: "fred"')
147
147
  end
148
148
 
@@ -152,23 +152,23 @@ describe Pickle::Session do
152
152
  it_should_behave_like "after storing a single user"
153
153
 
154
154
  it "created_model('the user: \"fred\"') should retrieve the user" do
155
- created_model('the user: "fred"').should == user
155
+ expect(created_model('the user: "fred"')).to eq(user)
156
156
  end
157
157
 
158
158
  it "created_model?('the user: \"shirl\"') should be false" do
159
- created_model?('the user: "shirl"').should == false
159
+ expect(created_model?('the user: "shirl"')).to eq(false)
160
160
  end
161
161
 
162
162
  it "model?('the user: \"shirl\"') should be false" do
163
- model?('the user: "shirl"').should == false
163
+ expect(model?('the user: "shirl"')).to eq(false)
164
164
  end
165
165
  end
166
166
  end
167
167
 
168
168
  describe "with hash" do
169
169
  it "should call user_factory.create({'foo' => 'bar'})" do
170
- user_factory.should_receive(:create).with({'foo' => 'bar'})
171
- create_model('a user', {'foo' => 'bar'}).should == user
170
+ expect(user_factory).to receive(:create).with({'foo' => 'bar'})
171
+ expect(create_model('a user', {'foo' => 'bar'})).to eq(user)
172
172
  end
173
173
 
174
174
  describe "after create," do
@@ -181,11 +181,11 @@ describe Pickle::Session do
181
181
 
182
182
  describe '#find_model' do
183
183
  before do
184
- Pickle::Adapter.stub!(:find_first_model).with(user_class, anything).and_return(user)
184
+ allow(Pickle::Adapter).to receive(:find_first_model).with(user_class, anything).and_return(user)
185
185
  end
186
186
 
187
187
  it "should call user_class.find :first, :conditions => {<fields>}" do
188
- find_model('a user', 'hair: "pink"').should == user
188
+ expect(find_model('a user', 'hair: "pink"')).to eq(user)
189
189
  end
190
190
 
191
191
  describe "after find," do
@@ -210,60 +210,60 @@ describe Pickle::Session do
210
210
  describe "create and find using plural_factory and table" do
211
211
  context "when given a table without a matching pickle ref column" do
212
212
  let :table do
213
- mock(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}])
213
+ double(:hashes => [{'name' => 'Fred'}, {'name' => 'Betty'}])
214
214
  end
215
215
 
216
216
  it "#create_models_from_table(<plural factory>, <table>) should call create_model for each of the table hashes with plain factory name and return the models" do
217
- should_receive(:create_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
218
- should_receive(:create_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
219
- create_models_from_table("users", table).should == [:fred, :betty]
217
+ expect(self).to receive(:create_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
218
+ expect(self).to receive(:create_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
219
+ expect(create_models_from_table("users", table)).to eq([:fred, :betty])
220
220
  end
221
221
 
222
222
  it "#find_models_from_table(<plural factory>, <table>) should call find_model for each of the table hashes with plain factory name and return the models" do
223
- should_receive(:find_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
224
- should_receive(:find_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
225
- find_models_from_table("users", table).should == [:fred, :betty]
223
+ expect(self).to receive(:find_model).with("user", 'name' => "Fred").once.ordered.and_return(:fred)
224
+ expect(self).to receive(:find_model).with("user", 'name' => "Betty").once.ordered.and_return(:betty)
225
+ expect(find_models_from_table("users", table)).to eq([:fred, :betty])
226
226
  end
227
227
  end
228
228
 
229
229
  context "when given a table with a matching pickle ref column" do
230
230
  let :table do
231
- mock(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}])
231
+ double(:hashes => [{'user' => "fred", 'name' => 'Fred'}, {'user' => "betty", 'name' => 'Betty'}])
232
232
  end
233
233
 
234
234
  it "#create_models_from_table(<plural factory>, <table>) should call create_model for each of the table hashes with labelled pickle ref" do
235
- should_receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
236
- should_receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
237
- create_models_from_table("users", table).should == [:fred, :betty]
235
+ expect(self).to receive(:create_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
236
+ expect(self).to receive(:create_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
237
+ expect(create_models_from_table("users", table)).to eq([:fred, :betty])
238
238
  end
239
239
 
240
240
  it "#find_models_from_table(<plural factory>, <table>) should call find_model for each of the table hashes with labelled pickle ref" do
241
- should_receive(:find_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
242
- should_receive(:find_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
243
- find_models_from_table("users", table).should == [:fred, :betty]
241
+ expect(self).to receive(:find_model).with("user \"fred\"", 'name' => "Fred").once.ordered.and_return(:fred)
242
+ expect(self).to receive(:find_model).with("user \"betty\"", 'name' => "Betty").once.ordered.and_return(:betty)
243
+ expect(find_models_from_table("users", table)).to eq([:fred, :betty])
244
244
  end
245
245
  end
246
246
  end
247
247
 
248
248
  describe "#find_model!" do
249
249
  it "should call find_model" do
250
- should_receive(:find_model).with('name', 'fields').and_return(user)
250
+ expect(self).to receive(:find_model).with('name', 'fields').and_return(user)
251
251
  find_model!('name', 'fields')
252
252
  end
253
253
 
254
254
  it "should call raise error if find_model returns nil" do
255
- should_receive(:find_model).with('name', 'fields').and_return(nil)
256
- lambda { find_model!('name', 'fields') }.should raise_error(Pickle::Session::ModelNotFoundError)
255
+ expect(self).to receive(:find_model).with('name', 'fields').and_return(nil)
256
+ expect { find_model!('name', 'fields') }.to raise_error(Pickle::Session::ModelNotFoundError)
257
257
  end
258
258
  end
259
259
 
260
260
  describe "#find_models" do
261
261
  before do
262
- Pickle::Adapter.stub!(:find_all_models).with(user_class, anything).and_return([user])
262
+ allow(Pickle::Adapter).to receive(:find_all_models).with(user_class, anything).and_return([user])
263
263
  end
264
264
 
265
265
  it "should call User.find :all, :conditions => {'hair' => 'pink'}" do
266
- find_models('user', 'hair: "pink"').should == [user]
266
+ expect(find_models('user', 'hair: "pink"')).to eq([user])
267
267
  end
268
268
 
269
269
  describe "after find," do
@@ -273,27 +273,27 @@ describe Pickle::Session do
273
273
  end
274
274
 
275
275
  it "should cope with spaces in the factory name (ie. it should make it canonical)" do
276
- pickle_parser.stub!(:canonical).and_return('user')
277
- pickle_parser.should_receive(:canonical).with('u ser').and_return('user')
278
- find_models('u ser', 'hair: "pink"').should == [user]
276
+ allow(pickle_parser).to receive(:canonical).and_return('user')
277
+ expect(pickle_parser).to receive(:canonical).with('u ser').and_return('user')
278
+ expect(find_models('u ser', 'hair: "pink"')).to eq([user])
279
279
  end
280
280
  end
281
281
 
282
282
  describe 'creating \'a super admin: "fred"\', then \'a user: "shirl"\', \'then 1 super_admin\' (super_admin is factory that returns users)' do
283
- let(:fred) { mock("fred", :class => user_class, :id => 2) }
284
- let(:shirl) { mock("shirl", :class => user_class, :id => 3) }
285
- let(:noname) { mock("noname", :class => user_class, :id => 4) }
283
+ let(:fred) { double("fred", :class => user_class, :id => 2) }
284
+ let(:shirl) { double("shirl", :class => user_class, :id => 3) }
285
+ let(:noname) { double("noname", :class => user_class, :id => 4) }
286
286
 
287
287
  if defined? ::FactoryGirl
288
- let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(mock(:build_class => user_class, :name => :super_admin)) }
288
+ let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(double(:build_class => user_class, :name => :super_admin)) }
289
289
  else
290
- let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(mock(:build_class => user_class, :factory_name => :super_admin)) }
290
+ let(:super_admin_factory) { Pickle::Adapter::FactoryGirl.new(double(:build_class => user_class, :factory_name => :super_admin)) }
291
291
  end
292
292
 
293
293
  before do
294
- config.stub(:factories).and_return(user_factory.name => user_factory, super_admin_factory.name => super_admin_factory)
295
- user_factory.stub(:create).and_return(shirl)
296
- super_admin_factory.stub(:create).and_return(fred, noname)
294
+ allow(config).to receive(:factories).and_return(user_factory.name => user_factory, super_admin_factory.name => super_admin_factory)
295
+ allow(user_factory).to receive(:create).and_return(shirl)
296
+ allow(super_admin_factory).to receive(:create).and_return(fred, noname)
297
297
  end
298
298
 
299
299
  def do_create_users
@@ -303,8 +303,8 @@ describe Pickle::Session do
303
303
  end
304
304
 
305
305
  it "should call Factory.create with <'super_admin'>, <'user'>, <'super_admin'>" do
306
- super_admin_factory.should_receive(:create).with({}).twice
307
- user_factory.should_receive(:create).with({}).once
306
+ expect(super_admin_factory).to receive(:create).with({}).twice
307
+ expect(user_factory).to receive(:create).with({}).once
308
308
  do_create_users
309
309
  end
310
310
 
@@ -314,44 +314,44 @@ describe Pickle::Session do
314
314
  end
315
315
 
316
316
  it "created_models('user') should == [fred, shirl, noname]" do
317
- created_models('user').should == [fred, shirl, noname]
317
+ expect(created_models('user')).to eq([fred, shirl, noname])
318
318
  end
319
319
 
320
320
  it "created_models('super_admin') should == [fred, noname]" do
321
- created_models('super_admin').should == [fred, noname]
321
+ expect(created_models('super_admin')).to eq([fred, noname])
322
322
  end
323
323
 
324
324
  describe "#created_model" do
325
325
  it "'that user' should be noname (the last user created - as super_admins are users)" do
326
- created_model('that user').should == noname
326
+ expect(created_model('that user')).to eq(noname)
327
327
  end
328
328
 
329
329
  it "'the super admin' should be noname (the last super admin created)" do
330
- created_model('that super admin').should == noname
330
+ expect(created_model('that super admin')).to eq(noname)
331
331
  end
332
332
 
333
333
  it "'the 1st super admin' should be fred" do
334
- created_model('the 1st super admin').should == fred
334
+ expect(created_model('the 1st super admin')).to eq(fred)
335
335
  end
336
336
 
337
337
  it "'the first user' should be fred" do
338
- created_model('the first user').should == fred
338
+ expect(created_model('the first user')).to eq(fred)
339
339
  end
340
340
 
341
341
  it "'the 2nd user' should be shirl" do
342
- created_model('the 2nd user').should == shirl
342
+ expect(created_model('the 2nd user')).to eq(shirl)
343
343
  end
344
344
 
345
345
  it "'the last user' should be noname" do
346
- created_model('the last user').should == noname
346
+ expect(created_model('the last user')).to eq(noname)
347
347
  end
348
348
 
349
349
  it "'the user: \"fred\" should be fred" do
350
- created_model('the user: "fred"').should == fred
350
+ expect(created_model('the user: "fred"')).to eq(fred)
351
351
  end
352
352
 
353
353
  it "'the user: \"shirl\" should be shirl" do
354
- created_model('the user: "shirl"').should == shirl
354
+ expect(created_model('the user: "shirl"')).to eq(shirl)
355
355
  end
356
356
  end
357
357
  end
@@ -360,73 +360,73 @@ describe Pickle::Session do
360
360
  describe "when 'the user: \"me\"' exists and there is a mapping from 'I', 'myself' => 'user: \"me\"" do
361
361
  before do
362
362
  self.pickle_parser = Pickle::Parser.new(:config => Pickle::Config.new {|c| c.map 'I', 'myself', :to => 'user: "me"'})
363
- config.stub(:factories).and_return('user' => user_factory)
364
- Pickle::Adapter.stub!(:get_model).with(user_class, anything).and_return(user)
365
- user_factory.stub!(:create).and_return(user)
363
+ allow(config).to receive(:factories).and_return('user' => user_factory)
364
+ allow(Pickle::Adapter).to receive(:get_model).with(user_class, anything).and_return(user)
365
+ allow(user_factory).to receive(:create).and_return(user)
366
366
  create_model('the user: "me"')
367
367
  end
368
368
 
369
369
  it 'model("I") should return the user' do
370
- model('I').should == user
370
+ expect(model('I')).to eq(user)
371
371
  end
372
372
 
373
373
  it 'model("myself") should return the user' do
374
- model('myself').should == user
374
+ expect(model('myself')).to eq(user)
375
375
  end
376
376
 
377
377
  it "#parser.parse_fields 'author: user \"JIM\"' should raise Error, as model deos not refer" do
378
- lambda { pickle_parser.parse_fields('author: user "JIM"') }.should raise_error
378
+ expect { pickle_parser.parse_fields('author: user "JIM"') }.to raise_error
379
379
  end
380
380
 
381
381
  it "#parser.parse_fields 'author: the user' should return {\"author\" => <user>}" do
382
- pickle_parser.parse_fields('author: the user').should == {"author" => user}
382
+ expect(pickle_parser.parse_fields('author: the user')).to eq({"author" => user})
383
383
  end
384
384
 
385
385
  it "#parser.parse_fields 'author: myself' should return {\"author\" => <user>}" do
386
- pickle_parser.parse_fields('author: myself').should == {"author" => user}
386
+ expect(pickle_parser.parse_fields('author: myself')).to eq({"author" => user})
387
387
  end
388
388
 
389
389
  it "#parser.parse_fields 'author: the user, approver: I, rating: \"5\"' should return {'author' => <user>, 'approver' => <user>, 'rating' => '5'}" do
390
- pickle_parser.parse_fields('author: the user, approver: I, rating: "5"').should == {'author' => user, 'approver' => user, 'rating' => '5'}
390
+ expect(pickle_parser.parse_fields('author: the user, approver: I, rating: "5"')).to eq({'author' => user, 'approver' => user, 'rating' => '5'})
391
391
  end
392
392
 
393
393
  it "#parser.parse_fields 'author: user: \"me\", approver: \"\"' should return {'author' => <user>, 'approver' => \"\"}" do
394
- pickle_parser.parse_fields('author: user: "me", approver: ""').should == {'author' => user, 'approver' => ""}
394
+ expect(pickle_parser.parse_fields('author: user: "me", approver: ""')).to eq({'author' => user, 'approver' => ""})
395
395
  end
396
396
  end
397
397
 
398
398
  describe "convert_models_to_attributes(ar_class, :user => <a user>)" do
399
399
  before do
400
- user.stub(:is_a?).with(ActiveRecord::Base).and_return(true)
400
+ allow(user).to receive(:is_a?).with(ActiveRecord::Base).and_return(true)
401
401
  end
402
402
 
403
403
  describe "(when ar_class has column 'user_id')" do
404
404
  let :ar_class do
405
- mock('ActiveRecord', :column_names => ['user_id'], :const_get => ActiveRecord::Base::PickleAdapter)
405
+ double('ActiveRecord', :column_names => ['user_id'], :const_get => ActiveRecord::Base::PickleAdapter)
406
406
  end
407
407
 
408
408
  it "should return {'user_id' => <the user.id>}" do
409
- convert_models_to_attributes(ar_class, :user => user).should == {'user_id' => user.id}
409
+ expect(convert_models_to_attributes(ar_class, :user => user)).to eq({'user_id' => user.id})
410
410
  end
411
411
  end
412
412
 
413
413
  describe "(when ar_class has columns 'user_id', 'user_type')" do
414
414
  let :ar_class do
415
- mock('ActiveRecord', :column_names => ['user_id', 'user_type'], :const_get => ActiveRecord::Base::PickleAdapter)
415
+ double('ActiveRecord', :column_names => ['user_id', 'user_type'], :const_get => ActiveRecord::Base::PickleAdapter)
416
416
  end
417
417
 
418
418
  it "should return {'user_id' => <the user.id>, 'user_type' => <the user.base_class>}" do
419
- user.class.should_receive(:base_class).and_return(mock('User base class', :name => 'UserBase'))
420
- convert_models_to_attributes(ar_class, :user => user).should == {'user_id' => user.id, 'user_type' => 'UserBase'}
419
+ expect(user.class).to receive(:base_class).and_return(double('User base class', :name => 'UserBase'))
420
+ expect(convert_models_to_attributes(ar_class, :user => user)).to eq({'user_id' => user.id, 'user_type' => 'UserBase'})
421
421
  end
422
422
  end
423
423
  end
424
424
 
425
425
  it "#model!('unknown') should raise informative error message" do
426
- lambda { model!('unknown') }.should raise_error(Pickle::Session::ModelNotKnownError, "The model: 'unknown' is not known in this scenario. Use #create_model to create, or #find_model to find, and store a reference in this scenario.")
426
+ expect { model!('unknown') }.to raise_error(Pickle::Session::ModelNotKnownError, "The model: 'unknown' is not known in this scenario. Use #create_model to create, or #find_model to find, and store a reference in this scenario.")
427
427
  end
428
428
 
429
429
  it "#created_model!('unknown') should raise informative error message" do
430
- lambda { created_model!('unknown') }.should raise_error(Pickle::Session::ModelNotKnownError)
430
+ expect { created_model!('unknown') }.to raise_error(Pickle::Session::ModelNotKnownError)
431
431
  end
432
432
  end