the 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +30 -0
  2. data/lib/the/model_steps.rb +41 -0
  3. data/lib/the.rb +26 -0
  4. data/the.gemspec +18 -0
  5. metadata +72 -0
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # The
2
+
3
+ *TLDR* a simple little DSL for Cucumber tests that work with ActiveRecord models.
4
+
5
+ ## Why?
6
+
7
+ I have a common pattern in my cukes whenever the step talks about "the User" or "the Fish". To me, the word "the" implies that there should only be one, so I always want to check:
8
+
9
+ Then /^the User should be married to susan$/ do
10
+ User.count.should == 1
11
+ User.first.should be_married_to('susan')
12
+ end
13
+
14
+ `The` is simple. It just gives you a nicer way to write that pattern:
15
+
16
+ Then /^the User should be married to susan$/ do
17
+ the(:user).should be_married_to('susan')
18
+ end
19
+
20
+ It's quite flexible, so you can pass `#the` a symbol, like in the example above, or a class, or a string of a class name. So, for example:
21
+
22
+ When /^the (\w+) eats the (\w+)$/ do |eater, eaten|
23
+ the(eater).eat(eaten)
24
+ end
25
+
26
+ In fact, there are a few steps defined for you, which you can have for yourself by calling...
27
+
28
+ require 'the/model_steps'
29
+
30
+ ...from somewhere inside your `features/step_definitions` folder.
@@ -0,0 +1,41 @@
1
+ Given /^there is a (#{Match::DomainEntity}) named "([^"]*)"$/ do |type, name|
2
+ Factory(type.underscore.to_sym, :name => name)
3
+ end
4
+
5
+ Given /^the following (#{Match::DomainEntity}):$/ do |type, attributes_table|
6
+ attributes_table.hashes.each do |attributes|
7
+ Factory(type.underscore.singularize.to_sym, attributes)
8
+ end
9
+ end
10
+
11
+ Then /^there should be (\d+) (#{Match::DomainEntity})$/ do |num, type|
12
+ type.constantize.count.should == num.to_i
13
+ end
14
+
15
+ Then /^the (#{Match::DomainEntity}) should have the following attributes:$/ do |type, table|
16
+ table.rows_hash.each do |key, value|
17
+ the(type).send(key).should == value
18
+ end
19
+ end
20
+
21
+ Then /^the (#{Match::DomainEntity}) should belong to the (#{Match::DomainEntity})$/ do |child_type, parent_type|
22
+ child = the(child_type)
23
+ parent = the(parent_type)
24
+ association_name = child_type.underscore.pluralize
25
+ parent.send(association_name).should include(child)
26
+ end
27
+
28
+ Then /^the following (#{Match::DomainEntity}) (should|should not) belong to the (#{Match::DomainEntity}):$/ do
29
+ |children_type, should, parent_type, children_table|
30
+ parent = the(parent_type)
31
+ association_name = children_type.underscore
32
+ child_type = children_type.singularize
33
+ children_table.hashes.each do |child_attributes|
34
+ child = the(child_type, child_attributes)
35
+ if should == 'should'
36
+ parent.send(association_name).should include(child)
37
+ else
38
+ parent.send(association_name).should_not include(child)
39
+ end
40
+ end
41
+ end
data/lib/the.rb ADDED
@@ -0,0 +1,26 @@
1
+ module Match
2
+ DomainEntity = /[A-z]\w+/
3
+ end
4
+
5
+ module The
6
+ module Dsl
7
+ def the(thing, conditions = {})
8
+ type = case thing
9
+ when Symbol
10
+ thing.to_s.classify.constantize
11
+ when String
12
+ thing.classify.constantize
13
+ when ActiveRecord::Base
14
+ thing
15
+ else
16
+ raise ArgumentError, thing.inspect
17
+ end
18
+ type.count(:conditions => conditions).should == 1
19
+ result = type.first(:conditions => conditions)
20
+ return yield result if block_given?
21
+ result
22
+ end
23
+ end
24
+ end
25
+
26
+ World(The::Dsl)
data/the.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "the"
3
+ s.version = "0.0.1"
4
+
5
+ s.required_rubygems_version = '>= 1.3.5'
6
+ s.authors = ["Matt Wynne"]
7
+ s.date = "2010-12-07"
8
+ s.description = %q{Simple and clean domain model DSL for tests}
9
+ s.email = "matt@mattwynne.net"
10
+
11
+ s.homepage = "http://github.com/mattwynne/the"
12
+ s.rdoc_options = ["--charset=UTF-8"]
13
+ s.rubygems_version = "1.3.6"
14
+ s.summary = %q{Cucumber plug-in for talking sense to your models}
15
+
16
+ s.require_path = "lib"
17
+ s.files = `git ls-files`.split("\n")
18
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Matt Wynne
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-07 00:00:00 +00:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Simple and clean domain model DSL for tests
23
+ email: matt@mattwynne.net
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - lib/the.rb
33
+ - lib/the/model_steps.rb
34
+ - the.gemspec
35
+ has_rdoc: true
36
+ homepage: http://github.com/mattwynne/the
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 17
59
+ segments:
60
+ - 1
61
+ - 3
62
+ - 5
63
+ version: 1.3.5
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Cucumber plug-in for talking sense to your models
71
+ test_files: []
72
+