factis 0.0.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +40 -4
- data/factis.gemspec +2 -2
- data/lib/factis/memory.rb +9 -7
- data/lib/factis/rspec.rb +9 -0
- data/lib/factis/version.rb +1 -1
- data/lib/generators/factis/cucumber_generator.rb +22 -0
- data/lib/generators/factis/rspec_generator.rb +17 -0
- data/lib/generators/templates/{factis_steps.rb → features/step_definitions/factis_steps.rb} +0 -0
- data/lib/generators/templates/{factis.rb → features/support/factis.rb} +0 -0
- data/lib/generators/templates/spec/support/factis.rb +1 -0
- data/spec/factis/memory_spec.rb +0 -8
- data/spec/factis_spec.rb +5 -1
- metadata +10 -8
- data/lib/generators/factis/install_generator.rb +0 -17
data/README.md
CHANGED
@@ -14,8 +14,12 @@ end
|
|
14
14
|
```
|
15
15
|
## Using with Rails ##
|
16
16
|
|
17
|
+
Included are a couple of generators to help you get rolling with Rails apps.
|
18
|
+
|
19
|
+
### Cucumber ###
|
20
|
+
|
17
21
|
```bash
|
18
|
-
rails generate factis:
|
22
|
+
rails generate factis:cucumber
|
19
23
|
```
|
20
24
|
|
21
25
|
Truth be told, this just installs some example Factis steps and a support file
|
@@ -29,7 +33,18 @@ one time, and then you should delete it. It's really just an example, and using
|
|
29
33
|
those steps in a feature will make your stakeholders hate you with the fury of
|
30
34
|
a thousand burning suns.
|
31
35
|
|
32
|
-
|
36
|
+
### Rspec ###
|
37
|
+
|
38
|
+
```bash
|
39
|
+
rails generate factis:rspec
|
40
|
+
```
|
41
|
+
|
42
|
+
This adds a Factis support file to your spec tree. The default configuration
|
43
|
+
is the same of that for Cucumber. It's important to note that Factis is
|
44
|
+
brought into Rspec via ```config.include``` so the DSL is available in
|
45
|
+
the examples, but not in the overall environment.
|
46
|
+
|
47
|
+
## Manual Cucumber ##
|
33
48
|
|
34
49
|
So, using Cucumber, but not Rails? Try this!
|
35
50
|
|
@@ -42,6 +57,27 @@ This gets you ready to use the DSL. Additionally, it forces Factis to forget
|
|
42
57
|
everything that you have told it to memorize after each scenario. Because stale
|
43
58
|
state information from one scenario to the next will make you a very sad panda.
|
44
59
|
|
60
|
+
## Manual Rspec ##
|
61
|
+
|
62
|
+
So, using Rspec, but not Rails? Try this!
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# spec/support/factis.rb
|
66
|
+
require 'factis/rspec'
|
67
|
+
```
|
68
|
+
|
69
|
+
If you're not using an all-inclusive support directory for your specs, you can
|
70
|
+
just toss that require into your spec_helper.rb or what have you.
|
71
|
+
|
72
|
+
This gets you ready to use the DSL. Additionally, it forces Factis to forget
|
73
|
+
everything that you have told it to memorize after each example. Because stale
|
74
|
+
state information from one example to the next will make you an increddibly
|
75
|
+
depressed platypus.
|
76
|
+
|
77
|
+
The DSL methods are injected into Rspec via include, so they're available
|
78
|
+
anywhere that example-level helpers are available. Primarily, in examples and
|
79
|
+
before/after callbacks.
|
80
|
+
|
45
81
|
## How Do I Use This Thing? ##
|
46
82
|
|
47
83
|
When I'm tracking state within a test, it's most likely a Cucumber feature.
|
@@ -138,8 +174,8 @@ so this thing got thrown together.
|
|
138
174
|
|
139
175
|
## Okay, So What's So Great About It? ##
|
140
176
|
|
141
|
-
Not much, really. It's
|
142
|
-
|
177
|
+
Not much, really. It's just a simple DSL that hides away the things that you
|
178
|
+
tell it to memorize and recalls them at your request. There is a generator
|
143
179
|
to get you up and running with Cucumber, but you should be able to use it with
|
144
180
|
just about any test framework that allows you to extend the global namespace
|
145
181
|
(a-la `World(Factis)`).
|
data/factis.gemspec
CHANGED
@@ -3,13 +3,13 @@ require File.expand_path('../lib/factis/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Dennis Walters"]
|
6
|
-
gem.email = ["
|
6
|
+
gem.email = ["dennis@elevatorup.com"]
|
7
7
|
gem.summary = %q{Discretely remember and recall facts in your tests}
|
8
8
|
gem.description = <<-EOD
|
9
9
|
Factis is a simple DSL for tracking state and such in your tests
|
10
10
|
without muddying up the global object space.
|
11
11
|
EOD
|
12
|
-
gem.homepage = "http://github.com/
|
12
|
+
gem.homepage = "http://github.com/elevatorup/factis"
|
13
13
|
gem.license = 'MIT'
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($\)
|
data/lib/factis/memory.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Factis
|
2
|
+
# This is the workhorse of Factis. It's what does the actual tracking of
|
3
|
+
# facts.
|
2
4
|
class Memory
|
3
5
|
|
4
6
|
class << self
|
5
7
|
private
|
6
8
|
def init_memory!
|
7
|
-
@facts
|
9
|
+
@facts ||= Hash.new
|
8
10
|
end
|
9
11
|
end
|
10
12
|
|
@@ -13,7 +15,7 @@ module Factis
|
|
13
15
|
# @return [Hash] all facts that have been stored
|
14
16
|
|
15
17
|
def self.all_facts
|
16
|
-
init_memory!
|
18
|
+
init_memory!
|
17
19
|
@facts
|
18
20
|
end
|
19
21
|
|
@@ -30,7 +32,7 @@ module Factis
|
|
30
32
|
# is not active.
|
31
33
|
|
32
34
|
def self.memorize(fact, content, options = {:overwrite => false})
|
33
|
-
init_memory!
|
35
|
+
init_memory!
|
34
36
|
if known_fact?(fact)
|
35
37
|
unless options[:overwrite] == true
|
36
38
|
raise %{Cannot memorize a fact more than once: '#{fact}'}
|
@@ -46,7 +48,7 @@ module Factis
|
|
46
48
|
# @return [Boolean] true if the key is known, false otherwise
|
47
49
|
|
48
50
|
def self.known_fact?(fact)
|
49
|
-
init_memory!
|
51
|
+
init_memory!
|
50
52
|
@facts.keys.include?(fact)
|
51
53
|
end
|
52
54
|
|
@@ -59,7 +61,7 @@ module Factis
|
|
59
61
|
# @raise [RuntimeError] if the key is not in the fact hash
|
60
62
|
|
61
63
|
def self.forget(fact)
|
62
|
-
init_memory!
|
64
|
+
init_memory!
|
63
65
|
unless known_fact?(fact)
|
64
66
|
raise %{Trying to forget an unknown fact: '#{fact}'}
|
65
67
|
end
|
@@ -75,7 +77,7 @@ module Factis
|
|
75
77
|
# @raise [RuntimeError] if the key is not in the fact hash
|
76
78
|
|
77
79
|
def self.recall(fact)
|
78
|
-
init_memory!
|
80
|
+
init_memory!
|
79
81
|
unless known_fact?(fact)
|
80
82
|
raise %{Trying to recall an unknown fact: '#{fact}'}
|
81
83
|
end
|
@@ -85,7 +87,7 @@ module Factis
|
|
85
87
|
# Clear the entire facts hash
|
86
88
|
|
87
89
|
def self.reset!
|
88
|
-
init_memory!
|
90
|
+
init_memory!
|
89
91
|
@facts.clear
|
90
92
|
end
|
91
93
|
end
|
data/lib/factis/rspec.rb
ADDED
data/lib/factis/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Factis
|
2
|
+
module Generators
|
3
|
+
|
4
|
+
# This is a Rails generator to add Factis support to Cucumber
|
5
|
+
|
6
|
+
class CucumberGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../../templates', __FILE__)
|
8
|
+
|
9
|
+
desc "Installs the Cucumber step and support files for Factis"
|
10
|
+
|
11
|
+
def copy_steps
|
12
|
+
template "features/step_definitions/factis_steps.rb",
|
13
|
+
"features/step_definitions/factis_steps.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_support
|
17
|
+
template "features/support/factis.rb",
|
18
|
+
"features/support/factis.rb"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Factis
|
2
|
+
module Generators
|
3
|
+
|
4
|
+
# This is a Rails generator to add Factis support to Rspec
|
5
|
+
|
6
|
+
class RspecGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../../templates', __FILE__)
|
8
|
+
|
9
|
+
desc "Installs the Rspec support files for Factis"
|
10
|
+
|
11
|
+
def copy_support
|
12
|
+
template "spec/support/factis.rb",
|
13
|
+
"spec/support/factis.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'factis/rspec'
|
data/spec/factis/memory_spec.rb
CHANGED
@@ -90,14 +90,6 @@ describe Factis::Memory do
|
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
-
describe %{.init_memory!} do
|
94
|
-
it %{should instantiate a new Hash for the memory} do
|
95
|
-
old = memory.all_facts.__id__
|
96
|
-
memory.class_eval('init_memory!')
|
97
|
-
memory.all_facts.__id__.should_not == old
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
93
|
describe %{.reset!} do
|
102
94
|
it %{should clear the memory} do
|
103
95
|
memory.memorize(fact, content)
|
data/spec/factis_spec.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'factis'
|
3
3
|
|
4
|
+
class Dummy
|
5
|
+
extend Factis
|
6
|
+
end
|
7
|
+
|
4
8
|
describe Factis do
|
5
9
|
describe %{DSL} do
|
6
|
-
let(:factis) {
|
10
|
+
let(:factis) {Dummy}
|
7
11
|
let(:fact) {"Joe"}
|
8
12
|
let(:content) {"likes pie"}
|
9
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: factis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
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: 2013-10-
|
12
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
description: ! " Factis is a simple DSL for tracking state and such in your tests\n
|
31
31
|
\ without muddying up the global object space.\n"
|
32
32
|
email:
|
33
|
-
-
|
33
|
+
- dennis@elevatorup.com
|
34
34
|
executables: []
|
35
35
|
extensions: []
|
36
36
|
extra_rdoc_files: []
|
@@ -46,14 +46,17 @@ files:
|
|
46
46
|
- lib/factis.rb
|
47
47
|
- lib/factis/cucumber.rb
|
48
48
|
- lib/factis/memory.rb
|
49
|
+
- lib/factis/rspec.rb
|
49
50
|
- lib/factis/version.rb
|
50
|
-
- lib/generators/factis/
|
51
|
-
- lib/generators/
|
52
|
-
- lib/generators/templates/factis_steps.rb
|
51
|
+
- lib/generators/factis/cucumber_generator.rb
|
52
|
+
- lib/generators/factis/rspec_generator.rb
|
53
|
+
- lib/generators/templates/features/step_definitions/factis_steps.rb
|
54
|
+
- lib/generators/templates/features/support/factis.rb
|
55
|
+
- lib/generators/templates/spec/support/factis.rb
|
53
56
|
- spec/factis/memory_spec.rb
|
54
57
|
- spec/factis_spec.rb
|
55
58
|
- spec/spec_helper.rb
|
56
|
-
homepage: http://github.com/
|
59
|
+
homepage: http://github.com/elevatorup/factis
|
57
60
|
licenses:
|
58
61
|
- MIT
|
59
62
|
post_install_message:
|
@@ -82,4 +85,3 @@ test_files:
|
|
82
85
|
- spec/factis/memory_spec.rb
|
83
86
|
- spec/factis_spec.rb
|
84
87
|
- spec/spec_helper.rb
|
85
|
-
has_rdoc:
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Factis
|
2
|
-
module Generators
|
3
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../../templates', __FILE__)
|
5
|
-
|
6
|
-
desc "Installs the Cucumber step and support files for Factis"
|
7
|
-
|
8
|
-
def copy_steps
|
9
|
-
template "factis_steps.rb", "features/step_definitions/factis_steps.rb"
|
10
|
-
end
|
11
|
-
|
12
|
-
def copy_support
|
13
|
-
template "factis.rb", "features/support/factis.rb"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|