factis 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ /.bundle
2
+ /log/*.log
3
+ /tmp
4
+ *~
5
+ *.swp
@@ -0,0 +1 @@
1
+ factis
@@ -0,0 +1 @@
1
+ 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ factis (0.0.0)
5
+ awesome_print
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ awesome_print (1.2.0)
11
+ builder (3.2.2)
12
+ cucumber (1.3.8)
13
+ builder (>= 2.1.2)
14
+ diff-lcs (>= 1.1.3)
15
+ gherkin (~> 2.12.1)
16
+ multi_json (>= 1.7.5, < 2.0)
17
+ multi_test (>= 0.0.2)
18
+ diff-lcs (1.2.4)
19
+ gherkin (2.12.1)
20
+ multi_json (~> 1.3)
21
+ multi_json (1.8.0)
22
+ multi_test (0.0.2)
23
+ rspec (2.14.1)
24
+ rspec-core (~> 2.14.0)
25
+ rspec-expectations (~> 2.14.0)
26
+ rspec-mocks (~> 2.14.0)
27
+ rspec-core (2.14.5)
28
+ rspec-expectations (2.14.3)
29
+ diff-lcs (>= 1.1.3, < 2.0)
30
+ rspec-mocks (2.14.3)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ cucumber
37
+ factis!
38
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Dennis Walters
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,107 @@
1
+ ## Factis ##
2
+
3
+ Ruby DSL for safely tracking facts through a test
4
+
5
+ ## Gem Setup ##
6
+
7
+ ```ruby
8
+ gem install factis
9
+
10
+ # Gemfile
11
+ group :test do
12
+ gem 'factis'
13
+ end
14
+ ```
15
+ ## Using with Rails ##
16
+
17
+ ```bash
18
+ rails generate factis:install
19
+ ```
20
+
21
+ Truth be told, this just installs some example Factis steps and a support file
22
+ for Cucumber. For the time being, it's on you to figure out how to use it with
23
+ other testing frameworks.
24
+
25
+ ### factis_steps.rb ###
26
+
27
+ Much like our once beloved web_steps.rb, you should read factis_steps.rb exactly
28
+ one time, and then you should delete it. It's really just an example, and using
29
+ those steps in a feature will make your stakeholders hate you with the fury of
30
+ a thousand burning suns.
31
+
32
+ ## Cucumber ##
33
+
34
+ So, using Cucumber, but not Rails? Try this!
35
+
36
+ ```ruby
37
+ # features/support/factis.env
38
+ require 'factis/cucumber'
39
+ ```
40
+
41
+ This gets you ready to use the DSL. Additionally, it forces Factis to forget
42
+ everything that you have told it to remember after each scenario. Because stale
43
+ state information from one scenario to the next will make you a very sad panda.
44
+
45
+ ## How Do I Use This Thing? ##
46
+
47
+ When I'm tracking state within a test, it's most likely a Cucumber feature.
48
+ That being the case, I'm going to use terminology from that side of the
49
+ experience. Here's everything that World gets when you use Factis.
50
+
51
+ ```ruby
52
+ # Let's remember that my brother, Joe, just loves pie.
53
+ remember_fact("What does Joe love?", "Joe loves pie.")
54
+
55
+ # Hey Factis, what does Joe love?
56
+ recall_fact("What does Joe love?")
57
+
58
+ # That's not very interesting. Let's forget about it.
59
+ forget_fact("What does Joe love?")
60
+
61
+ # Wait, what does Joe love again?
62
+ recall_fact("What does Joe love?")
63
+ => Trying to recall an unkown fact: 'What does Joe love?' (RuntimeError)
64
+
65
+ # Let's just forget everything.
66
+ clear_all_facts!
67
+
68
+ # So, what facts do we know?
69
+ all_facts
70
+ => {}
71
+
72
+ class Foo
73
+ end
74
+
75
+ # The content can be pretty much anything.
76
+ remember_fact(:some_foo, Foo.new)
77
+
78
+ # What's a foo?
79
+ recall_fact(:some_foo)
80
+ => #<Foo:0x007ffd84394728>
81
+ ```
82
+
83
+ ## So, Uh, Why? ##
84
+
85
+ There are two sides of this story, really:
86
+
87
+ * It's generally accepted that being able to track things over the course of an
88
+ indempotent test (a user's email address, the number of stars in the known
89
+ galaxy, etc) makes it easier to write tests. Rather than thinking "my email
90
+ address is user@example.com" repeatedly, you can just accept that you have
91
+ an email address.
92
+
93
+ * It's generally accepted that tracking things with instance variables over the
94
+ course of a test is a pretty bad scene. On top of generally muddying up the
95
+ object space, it makes it really easy to rely on state that's left over from
96
+ a previously-run scenario, forget to set them up in the first place, etc.
97
+
98
+ I've run into a lot of problems with tracking state in my tests in unsafe ways,
99
+ so this thing got thrown together.
100
+
101
+ ## Okay, So What's So Great About It? ##
102
+
103
+ Not much, really. It's really just a simple DSL that hides away the things that
104
+ you tell it to remember and recalls them at your request. There is a generator
105
+ to get you up and running with Cucumber, but you should be able to use it with
106
+ just about any test framework that allows you to extend the global namespace
107
+ (a-la `World(Factis)`).
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/factis/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dennis Walters"]
6
+ gem.email = ["pooster@gmail.com"]
7
+ gem.summary = %q{Discretely remember and recall facts in your tests}
8
+ gem.description = <<-EOD
9
+ Factis is a simple DSL for tracking state and such in your tests
10
+ without muddying up the global object space.
11
+ EOD
12
+ gem.homepage = "http://github.com/ess/factis"
13
+
14
+ gem.files = `git ls-files`.split($\)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.name = "factis"
18
+ gem.require_paths = ["lib"]
19
+ gem.version = Factis::VERSION
20
+
21
+ gem.add_dependency 'awesome_print'
22
+ gem.add_development_dependency 'cucumber'
23
+ #gem.add_development_dependency 'rspec-core'
24
+ #gem.add_development_dependency 'rspec-expectations'
25
+ #gem.add_development_dependency 'rspec-mocks'
26
+ gem.add_development_dependency 'rspec'
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'factis/memory'
2
+
3
+ module Factis
4
+
5
+ def clear_all_facts!
6
+ Factis::Memory.reset!
7
+ end
8
+
9
+ def all_facts
10
+ Factis::Memory.all_facts
11
+ end
12
+
13
+ def remember_fact(fact, content)
14
+ Factis::Memory.remember(fact, content)
15
+ end
16
+
17
+ def recall_fact(fact)
18
+ Factis::Memory.recall(fact)
19
+ end
20
+
21
+ def forget_fact(fact)
22
+ Factis::Memory.forget(fact)
23
+ end
24
+ end
@@ -0,0 +1,6 @@
1
+ require 'factis'
2
+ World(Factis)
3
+
4
+ After do
5
+ clear_all_facts!
6
+ end
@@ -0,0 +1,46 @@
1
+ require 'awesome_print'
2
+
3
+ module Factis
4
+ class Memory
5
+
6
+ def self.init_memory!
7
+ @facts = Hash.new
8
+ end
9
+
10
+ def self.all_facts
11
+ init_memory! if @facts.nil?
12
+ @facts
13
+ end
14
+
15
+ def self.remember(fact, content)
16
+ init_memory! if @facts.nil?
17
+ @facts[fact] = content
18
+ end
19
+
20
+ def self.known_fact?(fact)
21
+ init_memory! if @facts.nil?
22
+ @facts.keys.include?(fact)
23
+ end
24
+
25
+ def self.forget(fact)
26
+ init_memory! if @facts.nil?
27
+ unless known_fact?(fact)
28
+ raise %{Trying to forget an unknown fact: '#{fact}'}
29
+ end
30
+ @facts.delete(fact)
31
+ end
32
+
33
+ def self.recall(fact)
34
+ init_memory! if @facts.nil?
35
+ unless known_fact?(fact)
36
+ raise %{Trying to recall an unknown fact: '#{fact}'}
37
+ end
38
+ @facts[fact]
39
+ end
40
+
41
+ def self.reset!
42
+ init_memory! if @facts.nil?
43
+ @facts.clear
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Factis
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,6 @@
1
+ # Hey there! I'm sure that you'd really like to do things in this support file,
2
+ # but the fact of the matter is that there really isn't any configuration for
3
+ # Factis just yet. And there probably really never will be, because it's both
4
+ # simple and stubborn.
5
+
6
+ require 'factis/cucumber'
@@ -0,0 +1,20 @@
1
+ # These steps were installed by the Factis install generator to help get you
2
+ # started. You probably shouldn't really use these, and you should probably
3
+ # even go as far as to delete this file. Think of it the same way you'd think
4
+ # about the very far removed web_steps.rb from older versions of Cucumber.
5
+
6
+ Given %r{^I remember (.*?) is "(.*?)"$} do |fact, content|
7
+ remember_fact(fact, content)
8
+ end
9
+
10
+ Then %r{^I should recall (.*?) as "(.*?)"$} do |fact, expected_content|
11
+ recall_fact(fact).should == expected_content
12
+ end
13
+
14
+ When %r{^I forget (.*?)$} do |fact|
15
+ forget_fact(fact)
16
+ end
17
+
18
+ When %{I clear the facts memory} do
19
+ clear_all_facts!
20
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'factis/memory'
3
+
4
+ describe Factis::Memory do
5
+
6
+ let(:memory) {Factis::Memory}
7
+ let(:fact) {"Joe"}
8
+ let(:content) {"Likes pie"}
9
+
10
+ describe '.all_facts' do
11
+ it 'is a Hash' do
12
+ memory.all_facts.should be_a(Hash)
13
+ end
14
+ end
15
+
16
+ describe '.remember' do
17
+ context "when given a fact name and content" do
18
+ it "records the fact" do
19
+ memory.remember(fact, content)
20
+ memory.all_facts.keys.include?(fact).should be_true
21
+ memory.all_facts[fact].should == content
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '.known_fact?' do
27
+ before(:each) do
28
+ memory.remember(fact, content)
29
+ end
30
+
31
+ it "returns true for known facts" do
32
+ memory.known_fact?(fact).should be_true
33
+ end
34
+
35
+ it "returns false for unknown facts" do
36
+ memory.known_fact?(:unknown).should be_false
37
+ end
38
+ end
39
+
40
+ describe '.forget' do
41
+ before(:each) do
42
+ memory.remember(fact, content)
43
+ end
44
+
45
+
46
+
47
+ it "removes a known fact from memory" do
48
+ memory.forget(fact)
49
+ memory.known_fact?(fact).should be_false
50
+ end
51
+
52
+ it "raises an error when given an unknown fact" do
53
+ lambda {memory.forget("unknown fact")}.should raise_error
54
+ end
55
+ end
56
+
57
+ describe '.recall' do
58
+ before(:each) do
59
+ memory.remember(fact, content)
60
+ end
61
+
62
+ it "returns the content of a known fact" do
63
+ memory.recall(fact).should == content
64
+ end
65
+
66
+ it "raises an error when given an unknown fact" do
67
+ lambda {memory.recall(:unknown)}.should raise_error
68
+ end
69
+
70
+ end
71
+
72
+ describe '.init_memory!' do
73
+ it 'should instantiate a new Hash for the memory' do
74
+ old = memory.all_facts.__id__
75
+ memory.init_memory!
76
+ memory.all_facts.__id__.should_not == old
77
+ end
78
+ end
79
+
80
+ describe '.reset!' do
81
+ it 'should clear the memory' do
82
+ memory.remember(fact, content)
83
+ memory.known_fact?(fact).should be_true
84
+ memory.reset!
85
+ memory.known_fact?(fact).should be_false
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'factis'
3
+
4
+ describe Factis do
5
+ describe %{DSL} do
6
+ let(:factis) {Object.new.send(:extend, subject)}
7
+ let(:fact) {"Joe"}
8
+ let(:content) {"likes pie"}
9
+
10
+ describe %{#clear_all_facts!} do
11
+ it %{resets the Factis memory core} do
12
+ Factis::Memory.should_receive(:reset!)
13
+ factis.clear_all_facts!
14
+ end
15
+ end
16
+
17
+ describe %{#all_facts} do
18
+ it %{returns the contents of the Factis memory core} do
19
+ facts = {fact => content}
20
+ Factis::Memory.should_receive(:all_facts).and_return(facts)
21
+ factis.all_facts.should == facts
22
+ end
23
+ end
24
+
25
+ describe %{remember_fact} do
26
+ it %{stores the provided fact} do
27
+ Factis::Memory.should_receive(:remember).with(fact, content).and_call_original
28
+ factis.remember_fact(fact, content)
29
+ end
30
+ end
31
+
32
+ describe %{recall_fact} do
33
+ before(:each) {factis.remember_fact(fact, content)}
34
+
35
+ it %{recalls the provided fact if known} do
36
+ Factis::Memory.should_receive(:recall).with(fact).and_call_original
37
+ factis.recall_fact(fact).should == content
38
+ end
39
+
40
+ it %{raises an error if the fact is not known} do
41
+ lambda {factis.recall_fact(:unknown)}.should raise_error
42
+ end
43
+ end
44
+
45
+ describe %{forget_fact} do
46
+ before(:each) {factis.remember_fact(fact, content)}
47
+
48
+ it %{forgets the provided fact if known} do
49
+ Factis::Memory.should_receive(:forget).with(fact).and_call_original
50
+ factis.forget_fact(fact)
51
+ factis.all_facts.keys.include?(fact).should_not be_true
52
+ end
53
+
54
+ it %{raises an error if the fact is not known} do
55
+ lambda {factis.forget_fact(:unknown)}.should raise_error
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'rspec/mocks'
3
+ require 'rspec/expectations'
4
+
5
+ $:.unshift File.join(File.dirname(__FILE__), '..')
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_framework = :rspec
9
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dennis Walters
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: awesome_print
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: cucumber
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! " Factis is a simple DSL for tracking state and such in your tests\n
63
+ \ without muddying up the global object space.\n"
64
+ email:
65
+ - pooster@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .ruby-gemset
72
+ - .ruby-version
73
+ - Gemfile
74
+ - Gemfile.lock
75
+ - LICENSE
76
+ - README.md
77
+ - factis.gemspec
78
+ - lib/factis.rb
79
+ - lib/factis/cucumber.rb
80
+ - lib/factis/memory.rb
81
+ - lib/factis/version.rb
82
+ - lib/generators/factis/install_generator.rb
83
+ - lib/generators/templates/factis.rb
84
+ - lib/generators/templates/factis_steps.rb
85
+ - spec/factis/memory_spec.rb
86
+ - spec/factis_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://github.com/ess/factis
89
+ licenses: []
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.25
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Discretely remember and recall facts in your tests
112
+ test_files:
113
+ - spec/factis/memory_spec.rb
114
+ - spec/factis_spec.rb
115
+ - spec/spec_helper.rb