sandwich 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David Leal
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = sandwich
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 David Leal. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sandwich"
8
+ gem.summary = %Q{Cucumber helpers}
9
+ gem.description = %Q{Yup, cucumber helpers}
10
+ gem.email = "david@thedigitalants.com"
11
+ gem.homepage = "http://github.com/david/sandwich"
12
+ gem.authors = ["David Leal"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ begin
39
+ require 'yard'
40
+ YARD::Rake::YardocTask.new
41
+ rescue LoadError
42
+ task :yardoc do
43
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
44
+ end
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/sandwich.rb ADDED
@@ -0,0 +1,11 @@
1
+ module Sandwich
2
+ def self.require_all(dir)
3
+ Dir[File.join(File.dirname(__FILE__), %W(sandwich #{dir} *))].each do |f|
4
+ require "sandwich/#{dir}/#{File.basename(f, '.rb')}"
5
+ end
6
+ end
7
+
8
+ require_all('helpers')
9
+ require_all('ext')
10
+ require_all('cucumber')
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'pp'
2
+
3
+ Then Sandwich.regexps[:show_source] do
4
+ puts page.body
5
+ end
6
+
7
+ Then Sandwich.regexps[:show_all] do |targets|
8
+ targets.split(/,/).map do |target|
9
+ target.strip.singularize.classify.constantize.all.map { |item| pp item }
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ require 'sandwich/ext/string'
2
+ require 'sandwich/cucumber/world'
3
+ require 'sandwich/regexps'
4
+
5
+ Given Sandwich.regexps[:model] do |total, what|
6
+ class_for(what).tap do |model|
7
+ total.times { model.make }
8
+ end
9
+ end
10
+
11
+ Given Sandwich.regexps[:no_model] do |what|
12
+ class_for(what).delete_all
13
+ end
14
+
15
+ Given Sandwich.regexps[:model_with_attribute] do |total, what, attr, value|
16
+ class_for(what).tap do |model|
17
+ total.times { model.make(attr => value) }
18
+ end
19
+ end
20
+
21
+ Given Sandwich.regexps[:no_model_with_attribute] do |what, attr, value|
22
+ class_for(what).delete_all
23
+ end
24
+
25
+ Given Sandwich.regexps[:model_with_attributes] do |total, what, table|
26
+ class_for(what).tap do |model|
27
+ total.times { model.make(Hash[*table.raw.map { |k, v| [k.underscore, v] }.flatten]) }
28
+ end
29
+ end
30
+
31
+ Given Sandwich.regexps[:models_with_attributes] do |what, table|
32
+ class_for(what.singularize).tap do |model|
33
+ table.hashes.each do |h|
34
+ model.make(Hash[*h.each_pair.map { |(k, v)| [k.underscore, v] }.flatten])
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,9 @@
1
+ module Sandwich
2
+ module World
3
+ def class_for(name)
4
+ name.underscore.classify.constantize
5
+ end
6
+ end
7
+ end
8
+
9
+ World(Sandwich::World)
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Base.class_eval do
2
+ include Sandwich::Amounts
3
+ end
@@ -0,0 +1,20 @@
1
+ class String
2
+ alias_method :super_to_i, :to_i
3
+ alias_method :super_underscore, :underscore
4
+
5
+ def to_i
6
+ case self
7
+ when "a", "the", "an" then 1
8
+ when "no" then 0
9
+ else super_to_i
10
+ end
11
+ end
12
+
13
+ def underscore
14
+ super_underscore.gsub(/ +/, "_")
15
+ end
16
+
17
+ def times(&block)
18
+ to_i.times(&block)
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Sandwich
2
+ module Amounts
3
+ def method_missing(name, *args)
4
+ if name.to_s =~ /amount=$/
5
+ association = name.to_s.gsub("_amount=", "").pluralize
6
+
7
+ if respond_to?(association)
8
+ args.first.times { send(association).make }
9
+ else
10
+ super
11
+ end
12
+ else
13
+ super
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Sandwich
2
+ def self.regexps
3
+ # TODO extract (a|the|etc) to its own thing, so that it can be overridden
4
+
5
+ @regexps ||= {}.tap do |rx|
6
+ rx[:model] = /^(an?|the|\d+) (.+) exists?$/
7
+ rx[:no_model] = /^no (.+) exists?$/
8
+ rx[:model_with_attribute] = /^(an?|the|\d+) (.+) (?:with|in) (.+) "([^\"]*)" exists?$/
9
+ rx[:no_model_with_attribute] = /^no (.+) (?:with|in) (.+) "([^\"]*)" exists?$/
10
+ rx[:model_with_attributes] = /^(an?|the|\d+) (.+) exists with the following attributes:$/
11
+ rx[:models_with_attributes] = /^the following (.+) exist:$/
12
+ rx[:show_source] = /^show me the source$/
13
+ rs[:show_all] = /^show me all (.+)$/
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Sandwich" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'sandwich'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sandwich
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - David Leal
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-13 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: yard
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Yup, cucumber helpers
47
+ email: david@thedigitalants.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - LICENSE
59
+ - README.rdoc
60
+ - Rakefile
61
+ - VERSION
62
+ - lib/sandwich.rb
63
+ - lib/sandwich/cucumber/debug_steps.rb
64
+ - lib/sandwich/cucumber/model_steps.rb
65
+ - lib/sandwich/cucumber/world.rb
66
+ - lib/sandwich/ext/active_record.rb
67
+ - lib/sandwich/ext/string.rb
68
+ - lib/sandwich/helpers/amounts.rb
69
+ - lib/sandwich/regexps.rb
70
+ - spec/sandwich_spec.rb
71
+ - spec/spec.opts
72
+ - spec/spec_helper.rb
73
+ has_rdoc: true
74
+ homepage: http://github.com/david/sandwich
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.6
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: Cucumber helpers
103
+ test_files:
104
+ - spec/sandwich_spec.rb
105
+ - spec/spec_helper.rb