pickle 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/History.txt +7 -0
- data/README.rdoc +7 -10
- data/Rakefile +27 -46
- data/Todo.txt +0 -1
- data/VERSION +1 -1
- data/features/support/env.rb +1 -1
- data/lib/pickle/adapter.rb +18 -10
- data/lib/pickle/email.rb +1 -1
- data/pickle.gemspec +20 -21
- data/spec/{lib/pickle_adapter_spec.rb → pickle/adapter_spec.rb} +39 -20
- data/spec/{lib/pickle_config_spec.rb → pickle/config_spec.rb} +1 -1
- data/spec/{lib/pickle_email_parser_spec.rb → pickle/email/parser_spec.rb} +4 -2
- data/spec/{lib/pickle_email_spec.rb → pickle/email_spec.rb} +8 -4
- data/spec/{lib/pickle_parser_matchers_spec.rb → pickle/parser/matchers_spec.rb} +1 -1
- data/spec/pickle/parser_spec.rb +161 -0
- data/spec/{lib/pickle_path_spec.rb → pickle/path_spec.rb} +35 -26
- data/spec/{lib/pickle_session_spec.rb → pickle/session_spec.rb} +133 -130
- data/spec/{lib/pickle_spec.rb → pickle_spec.rb} +1 -1
- data/spec/spec_helper.rb +5 -37
- metadata +21 -22
- data/garlic.rb +0 -38
- data/spec/lib/pickle_parser_spec.rb +0 -154
data/.gitignore
CHANGED
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.2.6 - 5 Apr 2010
|
2
|
+
|
3
|
+
* 2 improvements
|
4
|
+
* running specs is now doable without being in a rails app - just do 'rake spec'
|
5
|
+
* running features is more straightforward, 'rake cucumber' then follow the instructions
|
6
|
+
|
7
|
+
|
1
8
|
== 0.2.5 - 17 Mar 2010
|
2
9
|
|
3
10
|
* 2 improvements
|
data/README.rdoc
CHANGED
@@ -45,18 +45,15 @@ It's tested against all stable branches of 2.x rails, and edge, with the latest
|
|
45
45
|
|
46
46
|
== Run the tests
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
Or, you can make a test rails app:
|
48
|
+
To run the specs do:
|
51
49
|
|
52
|
-
cd ~/wherever_you_work
|
53
|
-
rails pickle_test_project; cd pickle_test_project
|
54
|
-
script/generate rspec
|
55
|
-
script/generate cucumber --rspec
|
56
|
-
script/plugin install git://github.com/ianwhite/pickle.git
|
57
|
-
cd vendor/plugins/pickle
|
58
50
|
rake spec
|
59
|
-
|
51
|
+
|
52
|
+
To run the features do:
|
53
|
+
|
54
|
+
rake cucumber
|
55
|
+
|
56
|
+
The first time you do this, instructions will appear about how to set up a test rails app.
|
60
57
|
|
61
58
|
== Contributors
|
62
59
|
|
data/Rakefile
CHANGED
@@ -4,6 +4,7 @@ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base) and !$LOAD_PATH.includ
|
|
4
4
|
|
5
5
|
require 'spec/rake/spectask'
|
6
6
|
require 'spec/rake/verify_rcov'
|
7
|
+
require 'cucumber/rake/task'
|
7
8
|
|
8
9
|
$LOAD_PATH.unshift File.dirname(__FILE__) + '/lib'
|
9
10
|
require 'pickle/version'
|
@@ -29,61 +30,41 @@ end
|
|
29
30
|
namespace :rcov do
|
30
31
|
desc "Verify RCov threshold for #{PluginName}"
|
31
32
|
RCov::VerifyTask.new(:verify => :rcov) do |t|
|
32
|
-
t.threshold =
|
33
|
+
t.threshold = 99.23
|
33
34
|
t.index_html = File.join(File.dirname(__FILE__), 'doc/coverage/index.html')
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if File.exists?(cucumber_base) && plugins_base =~ /\/vendor\/plugins$/ # if we're in rails app
|
41
|
-
$:.unshift(cucumber_base)
|
42
|
-
require 'cucumber/rake/task'
|
43
|
-
|
44
|
-
desc "Run features for #{PluginName} (progress)"
|
45
|
-
Cucumber::Rake::Task.new(:features) do |t|
|
46
|
-
t.fork = true
|
47
|
-
t.cucumber_opts = ['--format', 'progress', '--require', 'features']
|
48
|
-
end
|
49
|
-
|
50
|
-
desc "Run features for #{PluginName} (full output)"
|
51
|
-
namespace :features do
|
52
|
-
Cucumber::Rake::Task.new(:full) do |t|
|
53
|
-
t.cucumber_opts = ['--format', 'pretty', '--require', 'features']
|
54
|
-
end
|
55
|
-
end
|
38
|
+
desc "Run features for #{PluginName} (progress)"
|
39
|
+
Cucumber::Rake::Task.new(:cucumber => [:cucumber_test_app]) do |t|
|
40
|
+
t.cucumber_opts = ['--format', 'pretty', '--require', 'features']
|
56
41
|
end
|
57
42
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
43
|
+
desc "setup a rails app for running cucumber"
|
44
|
+
file "cucumber_test_app" do
|
45
|
+
raise <<-EOD
|
46
|
+
|
47
|
+
** Please setup a test rails app in cucumber_test_app **
|
48
|
+
|
49
|
+
Until this is automated, do something like:
|
63
50
|
|
64
|
-
|
51
|
+
(make sure cucumber, cucumber-rails, rspec, rspec-rails, machinist, and factory_girl are all installed as gems)
|
65
52
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
53
|
+
rails cucumber_test_app
|
54
|
+
cd cucumber_test_app
|
55
|
+
script/generate rspec
|
56
|
+
script/generate cucumber
|
57
|
+
cd vendor/plugins
|
58
|
+
ln -s ../../.. pickle
|
59
|
+
cd ../../..
|
60
|
+
|
61
|
+
Then run
|
73
62
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
Grancher::Task.new(:push) do |g|
|
80
|
-
g.keep_all
|
81
|
-
g.directory 'doc', 'doc'
|
82
|
-
g.branch = 'gh-pages'
|
83
|
-
g.push_to = 'origin'
|
84
|
-
end
|
85
|
-
end
|
86
|
-
rescue LoadError
|
63
|
+
rake cucumber
|
64
|
+
|
65
|
+
** thanks! **
|
66
|
+
|
67
|
+
EOD
|
87
68
|
end
|
88
69
|
|
89
70
|
begin
|
data/Todo.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/features/support/env.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# files.
|
6
6
|
|
7
7
|
ENV["RAILS_ENV"] ||= "cucumber"
|
8
|
-
require File.expand_path(File.dirname(__FILE__) + '
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../cucumber_test_app/config/environment')
|
9
9
|
|
10
10
|
require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
|
11
11
|
require 'cucumber/rails/world'
|
data/lib/pickle/adapter.rb
CHANGED
@@ -11,10 +11,6 @@ module Pickle
|
|
11
11
|
class Adapter
|
12
12
|
attr_reader :name, :klass
|
13
13
|
|
14
|
-
def self.factories
|
15
|
-
raise NotImplementedError, "return an array of factory adapter objects"
|
16
|
-
end
|
17
|
-
|
18
14
|
def create(attrs = {})
|
19
15
|
raise NotImplementedError, "create and return an object with the given attributes"
|
20
16
|
end
|
@@ -22,12 +18,24 @@ module Pickle
|
|
22
18
|
cattr_writer :model_classes
|
23
19
|
self.model_classes = nil
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
class << self
|
22
|
+
def factories
|
23
|
+
raise NotImplementedError, "return an array of factory adapter objects"
|
24
|
+
end
|
25
|
+
|
26
|
+
def model_classes
|
27
|
+
@@model_classes ||= ::ActiveRecord::Base.send(:subclasses).select {|klass| suitable_for_pickle?(klass)}
|
28
|
+
end
|
29
|
+
|
30
|
+
# return true if a klass should be used by pickle
|
31
|
+
def suitable_for_pickle?(klass)
|
32
|
+
!klass.abstract_class? && klass.table_exists? && !framework_class?(klass)
|
33
|
+
end
|
34
|
+
|
35
|
+
# return true if the passed class is a special framework class
|
36
|
+
def framework_class?(klass)
|
37
|
+
((defined?(CGI::Session::ActiveRecordStore::Session) && klass == CGI::Session::ActiveRecordStore::Session)) ||
|
38
|
+
((defined?(::ActiveRecord::SessionStore::Session) && klass == ::ActiveRecord::SessionStore::Session))
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
data/lib/pickle/email.rb
CHANGED
@@ -34,7 +34,7 @@ module Pickle
|
|
34
34
|
# web browser if on OS X. (depends on webrat)
|
35
35
|
def save_and_open_emails
|
36
36
|
emails_to_open = @emails || emails
|
37
|
-
filename = "
|
37
|
+
filename = "webrat-email-#{Time.now.to_i}.html"
|
38
38
|
File.open(filename, "w") do |f|
|
39
39
|
emails_to_open.each_with_index do |e, i|
|
40
40
|
f.write "<h1>Email #{i+1}</h1><pre>#{e}</pre><hr />"
|
data/pickle.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pickle}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ian White"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-05}
|
13
13
|
s.description = %q{Easy model creation and reference in your cucumber features}
|
14
14
|
s.email = %q{ian.w.white@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -46,7 +46,6 @@ Gem::Specification.new do |s|
|
|
46
46
|
"features/support/paths.rb",
|
47
47
|
"features/support/pickle.rb",
|
48
48
|
"features/support/pickle_app.rb",
|
49
|
-
"garlic.rb",
|
50
49
|
"init.rb",
|
51
50
|
"lib/pickle.rb",
|
52
51
|
"lib/pickle/adapter.rb",
|
@@ -69,15 +68,15 @@ Gem::Specification.new do |s|
|
|
69
68
|
"rails_generators/pickle/templates/paths.rb",
|
70
69
|
"rails_generators/pickle/templates/pickle.rb",
|
71
70
|
"rails_generators/pickle/templates/pickle_steps.rb",
|
72
|
-
"spec/
|
73
|
-
"spec/
|
74
|
-
"spec/
|
75
|
-
"spec/
|
76
|
-
"spec/
|
77
|
-
"spec/
|
78
|
-
"spec/
|
79
|
-
"spec/
|
80
|
-
"spec/
|
71
|
+
"spec/pickle/adapter_spec.rb",
|
72
|
+
"spec/pickle/config_spec.rb",
|
73
|
+
"spec/pickle/email/parser_spec.rb",
|
74
|
+
"spec/pickle/email_spec.rb",
|
75
|
+
"spec/pickle/parser/matchers_spec.rb",
|
76
|
+
"spec/pickle/parser_spec.rb",
|
77
|
+
"spec/pickle/path_spec.rb",
|
78
|
+
"spec/pickle/session_spec.rb",
|
79
|
+
"spec/pickle_spec.rb",
|
81
80
|
"spec/spec_helper.rb"
|
82
81
|
]
|
83
82
|
s.homepage = %q{http://github.com/ianwhite/pickle/tree}
|
@@ -86,15 +85,15 @@ Gem::Specification.new do |s|
|
|
86
85
|
s.rubygems_version = %q{1.3.6}
|
87
86
|
s.summary = %q{Easy model creation and reference in your cucumber features}
|
88
87
|
s.test_files = [
|
89
|
-
"spec/
|
90
|
-
"spec/
|
91
|
-
"spec/
|
92
|
-
"spec/
|
93
|
-
"spec/
|
94
|
-
"spec/
|
95
|
-
"spec/
|
96
|
-
"spec/
|
97
|
-
"spec/
|
88
|
+
"spec/pickle/adapter_spec.rb",
|
89
|
+
"spec/pickle/config_spec.rb",
|
90
|
+
"spec/pickle/email/parser_spec.rb",
|
91
|
+
"spec/pickle/email_spec.rb",
|
92
|
+
"spec/pickle/parser/matchers_spec.rb",
|
93
|
+
"spec/pickle/parser_spec.rb",
|
94
|
+
"spec/pickle/path_spec.rb",
|
95
|
+
"spec/pickle/session_spec.rb",
|
96
|
+
"spec/pickle_spec.rb",
|
98
97
|
"spec/spec_helper.rb"
|
99
98
|
]
|
100
99
|
|
@@ -1,4 +1,8 @@
|
|
1
|
-
require File.
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'activerecord'
|
4
|
+
require 'factory_girl'
|
5
|
+
require 'machinist/active_record'
|
2
6
|
|
3
7
|
describe Pickle::Adapter do
|
4
8
|
it ".factories should raise NotImplementedError" do
|
@@ -9,32 +13,47 @@ describe Pickle::Adapter do
|
|
9
13
|
lambda{ Pickle::Adapter.new.create }.should raise_error(NotImplementedError)
|
10
14
|
end
|
11
15
|
|
12
|
-
describe ".
|
16
|
+
describe ".suitable_for_pickle?(klass)" do
|
17
|
+
let :klass do
|
18
|
+
mock('Class', :abstract_class? => false, :table_exists? => true)
|
19
|
+
end
|
20
|
+
|
13
21
|
before do
|
14
|
-
Pickle::Adapter.
|
22
|
+
Pickle::Adapter.stub!(:framework_class?).and_return(false)
|
15
23
|
end
|
16
24
|
|
17
|
-
|
18
|
-
|
19
|
-
Pickle::Adapter.model_classes.should_not include(CGI::Session::ActiveRecordStore)
|
20
|
-
end
|
25
|
+
it "a non abstract class that has a table, and is not a framework class, is suitable_for_pickle" do
|
26
|
+
Pickle::Adapter.should be_suitable_for_pickle(klass)
|
21
27
|
end
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
28
|
+
|
29
|
+
it "an abtract_class is not suitable_for_pickle" do
|
30
|
+
klass.stub!(:abstract_class?).and_return(true)
|
31
|
+
Pickle::Adapter.should_not be_suitable_for_pickle(klass)
|
27
32
|
end
|
33
|
+
|
34
|
+
it "a class with no table is not suitable_for_pickle" do
|
35
|
+
klass.stub!(:table_exists?).and_return(false)
|
36
|
+
Pickle::Adapter.should_not be_suitable_for_pickle(klass)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "an frame_work class is not suitable_for_pickle" do
|
40
|
+
Pickle::Adapter.should_receive(:framework_class?).with(klass).and_return(true)
|
41
|
+
Pickle::Adapter.should_not be_suitable_for_pickle(klass)
|
42
|
+
end
|
43
|
+
end
|
28
44
|
|
29
|
-
|
30
|
-
|
31
|
-
Pickle::Adapter.model_classes
|
45
|
+
describe ".model_classes" do
|
46
|
+
before do
|
47
|
+
Pickle::Adapter.model_classes = nil
|
32
48
|
end
|
33
|
-
|
34
|
-
it "should
|
35
|
-
|
36
|
-
|
37
|
-
Pickle::Adapter.
|
49
|
+
|
50
|
+
it "should only include #suitable_for_pickle classes" do
|
51
|
+
klass1 = Class.new(ActiveRecord::Base)
|
52
|
+
klass2 = Class.new(ActiveRecord::Base)
|
53
|
+
Pickle::Adapter.should_receive(:suitable_for_pickle?).with(klass1).and_return(true)
|
54
|
+
Pickle::Adapter.should_receive(:suitable_for_pickle?).with(klass2).and_return(false)
|
55
|
+
Pickle::Adapter.model_classes.should include(klass1)
|
56
|
+
Pickle::Adapter.model_classes.should_not include(klass2)
|
38
57
|
end
|
39
58
|
end
|
40
59
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
require File.
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
require 'pickle/email/parser'
|
2
4
|
|
3
5
|
describe Pickle::Email::Parser do
|
4
6
|
include Pickle::Parser::Matchers
|
@@ -46,4 +48,4 @@ describe Pickle::Email::Parser do
|
|
46
48
|
match[1].should == 'last'
|
47
49
|
end
|
48
50
|
end
|
49
|
-
end
|
51
|
+
end
|
@@ -1,4 +1,8 @@
|
|
1
|
-
require File.
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'pickle/email'
|
4
|
+
require 'pickle/email/parser'
|
5
|
+
require 'actionmailer'
|
2
6
|
|
3
7
|
describe Pickle::Email do
|
4
8
|
include Pickle::Session
|
@@ -120,11 +124,11 @@ describe Pickle::Email do
|
|
120
124
|
|
121
125
|
it "should create a file in Rails/tmp with the emails in it" do
|
122
126
|
save_and_open_emails
|
123
|
-
File.read("
|
127
|
+
File.read("webrat-email-#{@now.to_i}.html").should == "<h1>Email 1</h1><pre>Contents of Email 1</pre><hr />"
|
124
128
|
end
|
125
129
|
|
126
130
|
it "should call open_in_browser on created tmp file" do
|
127
|
-
should_receive(:open_in_browser).with("
|
131
|
+
should_receive(:open_in_browser).with("webrat-email-#{@now.to_i}.html")
|
128
132
|
save_and_open_emails
|
129
133
|
end
|
130
134
|
end
|
@@ -150,4 +154,4 @@ describe Pickle::Email do
|
|
150
154
|
click_first_link_in_email(@email1)
|
151
155
|
end
|
152
156
|
end
|
153
|
-
end
|
157
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Pickle::Parser do
|
4
|
+
before do
|
5
|
+
@parser = Pickle::Parser.new(:config => Pickle::Config.new)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should raise error when created with no config" do
|
9
|
+
lambda{ Pickle::Parser.new }.should raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "when a 'user' factory exists in config" do
|
13
|
+
before do
|
14
|
+
@parser.config.stub(:factories).and_return('user' => mock('User'))
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'misc regexps' do
|
18
|
+
describe '/^#{capture_model} exists/' do
|
19
|
+
before do
|
20
|
+
@regexp = /^(#{@parser.capture_model}) exists$/
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should match 'a user exists'" do
|
24
|
+
'a user exists'.should match(@regexp)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should caputure 'a user' from 'a user exists'" do
|
28
|
+
'a user exists'.match(@regexp)[1].should == 'a user'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#parse_field' do
|
34
|
+
it "should return {'a' => 'b'} for 'a: \"b\"'" do
|
35
|
+
@parser.parse_field('a: "b"').should == {'a' => 'b'}
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise error for invalid field 'a : b'" do
|
39
|
+
lambda { @parser.parse_field('a : b') }.should raise_error(ArgumentError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#parse_fields' do
|
44
|
+
it 'should return {} for blank argument' do
|
45
|
+
@parser.parse_fields(nil).should == {}
|
46
|
+
@parser.parse_fields('').should == {}
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should raise error for invalid argument' do
|
50
|
+
lambda { @parser.parse_fields('foo foo') }.should raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it '(\'foo: "bar"\') should == { "foo" => "bar"}' do
|
54
|
+
@parser.parse_fields('foo: "bar"').should == { "foo" => "bar"}
|
55
|
+
end
|
56
|
+
|
57
|
+
it '("bool: true") should == { "bool" => true}' do
|
58
|
+
@parser.parse_fields('bool: true').should == {"bool" => true}
|
59
|
+
end
|
60
|
+
|
61
|
+
it '("bool: false") should == { "bool" => false}' do
|
62
|
+
@parser.parse_fields('bool: false').should == {"bool" => false}
|
63
|
+
end
|
64
|
+
|
65
|
+
it '("int: 10") should == { "int" => 10 }' do
|
66
|
+
@parser.parse_fields('int: 10').should == {"int" => 10}
|
67
|
+
end
|
68
|
+
|
69
|
+
it '("float: 10.1") should == { "float" => 10.1 }' do
|
70
|
+
@parser.parse_fields('float: 10.1').should == {"float" => 10.1}
|
71
|
+
end
|
72
|
+
|
73
|
+
it '(\'foo: "bar", bar_man: "wonga wonga", gump: 123\') should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}' do
|
74
|
+
@parser.parse_fields('foo: "bar", bar_man: "wonga wonga", gump: 123').should == {"foo" => "bar", "bar_man" => "wonga wonga", "gump" => 123}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#parse_model' do
|
79
|
+
it '("a user") should == ["user", ""]' do
|
80
|
+
@parser.parse_model("a user").should == ["user", ""]
|
81
|
+
end
|
82
|
+
|
83
|
+
it '("the user") should == ["user", ""]' do
|
84
|
+
@parser.parse_model("the user").should == ["user", ""]
|
85
|
+
end
|
86
|
+
|
87
|
+
it '("1 user") should == ["user", ""]' do
|
88
|
+
@parser.parse_model("1 user").should == ["user", ""]
|
89
|
+
end
|
90
|
+
|
91
|
+
it '(\'an user: "jim jones"\') should == ["user", "jim_jones"]' do
|
92
|
+
@parser.parse_model('an user: "jim jones"').should == ["user", "jim_jones"]
|
93
|
+
end
|
94
|
+
|
95
|
+
it '(\'that user: "herbie"\') should == ["user", "herbie"]' do
|
96
|
+
@parser.parse_model('that user: "herbie"').should == ["user", "herbie"]
|
97
|
+
end
|
98
|
+
|
99
|
+
it '(\'the 12th user\') should == ["user", 11]' do
|
100
|
+
@parser.parse_model('the 12th user').should == ["user", 11]
|
101
|
+
end
|
102
|
+
|
103
|
+
it '(\'the last user\') should == ["user", -1]' do
|
104
|
+
@parser.parse_model('the last user').should == ["user", -1]
|
105
|
+
end
|
106
|
+
|
107
|
+
it '("the first user") should == ["user", 0]' do
|
108
|
+
@parser.parse_model('the first user').should == ["user", 0]
|
109
|
+
end
|
110
|
+
|
111
|
+
it '("the 1st user") should == ["user", 0]' do
|
112
|
+
@parser.parse_model('the 1st user').should == ["user", 0]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#parse_index" do
|
117
|
+
it '("1st") should == 0' do
|
118
|
+
@parser.parse_index("1st").should == 0
|
119
|
+
end
|
120
|
+
|
121
|
+
it '("24th") should == 23' do
|
122
|
+
@parser.parse_index("24th").should == 23
|
123
|
+
end
|
124
|
+
it '("first") should == 0' do
|
125
|
+
@parser.parse_index("first").should == 0
|
126
|
+
end
|
127
|
+
|
128
|
+
it '("last") should == -1' do
|
129
|
+
@parser.parse_index("last").should == -1
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "customised mappings" do
|
135
|
+
describe "config maps 'I|myself' to 'user: \"me\"'" do
|
136
|
+
before do
|
137
|
+
@config = Pickle::Config.new do |c|
|
138
|
+
c.map 'I', 'myself', :to => 'user: "me"'
|
139
|
+
end
|
140
|
+
@parser = Pickle::Parser.new(:config => @config)
|
141
|
+
@parser.config.stub(:factories).and_return('user' => mock('User'))
|
142
|
+
end
|
143
|
+
|
144
|
+
it "'I' should match /\#{match_model}/" do
|
145
|
+
'I'.should match(/#{@parser.match_model}/)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "'myself' should match /\#{match_model}/" do
|
149
|
+
'myself'.should match(/#{@parser.match_model}/)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "parse_model('I') should == ['user', 'me']" do
|
153
|
+
@parser.parse_model('I').should == ["user", "me"]
|
154
|
+
end
|
155
|
+
|
156
|
+
it "parse_model('myself') should == ['user', 'me']" do
|
157
|
+
@parser.parse_model('myself').should == ["user", "me"]
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|