mountain_berry_fields 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.gitignore +19 -0
  2. data/.simplecov +12 -0
  3. data/Gemfile +2 -0
  4. data/LICENSE +22 -0
  5. data/Rakefile +30 -0
  6. data/Readme.md +184 -0
  7. data/Readme.md.mountain_berry_fields +197 -0
  8. data/bin/mountain_berry_fields +9 -0
  9. data/features/context_block.feature +73 -0
  10. data/features/cwd_is_dir_of_mbf_file.feature +16 -0
  11. data/features/rake_task.feature +46 -0
  12. data/features/setup_block.feature +36 -0
  13. data/features/step_definitions/steps.rb +46 -0
  14. data/features/support/env.rb +76 -0
  15. data/lib/mountain_berry_fields.rb +89 -0
  16. data/lib/mountain_berry_fields/command_line_interaction.rb +13 -0
  17. data/lib/mountain_berry_fields/evaluator.rb +90 -0
  18. data/lib/mountain_berry_fields/parser.rb +101 -0
  19. data/lib/mountain_berry_fields/rake_task.rb +12 -0
  20. data/lib/mountain_berry_fields/test.rb +88 -0
  21. data/lib/mountain_berry_fields/test/always_fail.rb +21 -0
  22. data/lib/mountain_berry_fields/test/always_pass.rb +19 -0
  23. data/lib/mountain_berry_fields/version.rb +3 -0
  24. data/mountain_berry_fields.gemspec +29 -0
  25. data/readme_helper.rb +205 -0
  26. data/spec/command_line_interaction_spec.rb +16 -0
  27. data/spec/evaluator_spec.rb +170 -0
  28. data/spec/mock_substitutability_spec.rb +25 -0
  29. data/spec/mountain_berry_fields_spec.rb +147 -0
  30. data/spec/parser_spec.rb +139 -0
  31. data/spec/ruby_syntax_checker_spec.rb +27 -0
  32. data/spec/spec_helper.rb +104 -0
  33. data/spec/test/always_fail_spec.rb +25 -0
  34. data/spec/test/always_pass_spec.rb +15 -0
  35. data/spec/test/strategy_spec.rb +48 -0
  36. data/spec/test/test_spec.rb +22 -0
  37. metadata +209 -0
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe MountainBerryFields::Test::RubySyntaxChecker do
4
+ it 'implements the SyntaxChecker interface' do
5
+ Mock::SyntaxChecker.should substitute_for described_class
6
+ end
7
+
8
+ describe '#valid?' do
9
+ it 'returns false for invalid syntax' do
10
+ described_class.new("{").should_not be_valid
11
+ end
12
+
13
+ it 'returns true for valid syntax' do
14
+ described_class.new("{}").should be_valid
15
+ end
16
+ end
17
+
18
+ describe '#invalid_message' do
19
+ it 'returns whatever Ruby gave it on the command line, followed by the original file' do
20
+ described_class.new("{").invalid_message.should ==
21
+ "-:1: syntax error, unexpected $end, expecting '}'\n"\
22
+ "\n" \
23
+ "original file:\n" \
24
+ "{"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,104 @@
1
+ require 'simplecov'
2
+
3
+ require 'mountain_berry_fields'
4
+ require 'mountain_berry_fields/command_line_interaction'
5
+
6
+ require 'stringio'
7
+ require 'surrogate/rspec'
8
+
9
+
10
+ RSpec::Matchers.define :pass do
11
+ match { |matcher| matcher.pass? }
12
+ end
13
+
14
+ module Mock
15
+ class SyntaxChecker
16
+ Surrogate.endow self
17
+ define(:initialize) { |syntax| }
18
+ define(:valid?) { true }
19
+ define(:invalid_message) { "shit ain't valid" }
20
+ end
21
+
22
+ class File
23
+ Surrogate.endow self do
24
+ define(:exist?) { true }
25
+ define(:write) { true }
26
+ define(:read) { "file contents" }
27
+ end
28
+ end
29
+
30
+ class Dir
31
+ Surrogate.endow self do
32
+ define(:chdir) { |dir, &block| block.call }
33
+ define(:mktmpdir) { |prefix, &block| block.call }
34
+ end
35
+ end
36
+
37
+ module Process
38
+ class Status
39
+ Surrogate.endow self
40
+ define(:success?) { true }
41
+ end
42
+ end
43
+
44
+ class Open3
45
+ Surrogate.endow self do
46
+ define(:capture3) { |invocation| ["stdout", "stderr", @exitstatus||Process::Status.new] }
47
+ end
48
+
49
+
50
+ def self.exit_with_failure!
51
+ @exitstatus = Process::Status.new.will_have_success? false
52
+ self
53
+ end
54
+
55
+ def self.exit_with_success!
56
+ @exitstatus = Process::Status.new.will_have_success? true
57
+ self
58
+ end
59
+ end
60
+
61
+ class Interaction
62
+ Surrogate.endow self
63
+ define(:declare_failure) { }
64
+ end
65
+
66
+ class Evaluator
67
+ Surrogate.endow self do
68
+ define(:visible_commands) { [:visible] }
69
+ define(:invisible_commands) { [:invisible] }
70
+ end
71
+
72
+ define(:initialize) { @document = '' }
73
+ define(:tests_pass?) { true }
74
+ define(:test) { |test, &block| block.call }
75
+ define(:failure_message) { 'some failure message' }
76
+ define(:failure_name) { 'failing test name' }
77
+ define(:document)
78
+
79
+ def inspect
80
+ '#<MOCK EVALUATOR>'
81
+ end
82
+ end
83
+
84
+ class Parser
85
+ Surrogate.endow self
86
+ define(:initialize) {}
87
+ define(:parse) { 'some body' }
88
+ define(:parsed) { parse }
89
+
90
+ def inspect
91
+ '#<MOCK PARSER>'
92
+ end
93
+ end
94
+ end
95
+
96
+ MountainBerryFields.override(:file_class) { Mock::File.clone }
97
+ MountainBerryFields.override(:dir_class) { Mock::Dir.clone }
98
+ MountainBerryFields.override(:interaction) { Mock::Interaction.new }
99
+ MountainBerryFields.override(:evaluator_class) { Mock::Evaluator.clone }
100
+ MountainBerryFields.override(:parser_class) { Mock::Parser.clone }
101
+
102
+ MountainBerryFields::CommandLineInteraction.override(:stderr) { StringIO.new }
103
+ MountainBerryFields::Test::RSpec.override(:syntax_checker_class) { Mock::SyntaxChecker }
104
+ MountainBerryFields::Test::MagicComments.override(:syntax_checker_class) { Mock::SyntaxChecker }
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ test_class = MountainBerryFields::Test
4
+ describe test_class::AlwaysFail do
5
+ it 'is registered it the strategy list under :always_pass' do
6
+ test_class::Strategy.for(:always_fail).should == described_class
7
+ end
8
+
9
+ it 'evaluates the code' do
10
+ $a = nil
11
+ described_class.new('$a=1').pass?
12
+ $a.should == 1
13
+ end
14
+
15
+ specify '#pass? evaluates the code and returns false even in the face of bullshit' do
16
+ described_class.new("raise Exception, 'this will still pass'").should_not pass
17
+ $abc = ''
18
+ described_class.new("$abc=123").should_not pass
19
+ $abc.should == 123
20
+ end
21
+
22
+ specify '#failure_message returns some bullshit about failing' do
23
+ described_class.new('').failure_message.should be_a_kind_of String
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ test_class = MountainBerryFields::Test
4
+ describe test_class::AlwaysPass do
5
+ it 'is registered it the strategy list under :always_pass' do
6
+ test_class::Strategy.for(:always_pass).should == described_class
7
+ end
8
+
9
+ specify '#pass? evaluates the code and returns true even in the face of bullshit' do
10
+ described_class.new("raise Exception, 'this will still pass'").should pass
11
+ $abc = ''
12
+ described_class.new("$abc=123").should pass
13
+ $abc.should == 123
14
+ end
15
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ described_class = MountainBerryFields::Test::Strategy
4
+
5
+ describe described_class do
6
+ it 'is a module that you can mix into any class that wants to be a strategy' do
7
+ described_class.should be_a_kind_of Module
8
+ end
9
+
10
+ let(:strategy) { 'some strategy' }
11
+ before { described_class.unregister :abc }
12
+
13
+ describe 'registration' do
14
+ specify 'a strategy can register itself with the .register method' do
15
+ described_class.register :abc, strategy
16
+ described_class.should be_registered :abc
17
+ described_class.should be_registered 'abc'
18
+ end
19
+
20
+ specify 'a strategy can unregister itself with the .unregister method' do
21
+ described_class.register :abc, strategy
22
+ described_class.unregister 'abc'
23
+ expect { described_class.for :abc }.to raise_error NameError, /abc/
24
+ end
25
+
26
+ specify 'a strategy can be retrieved with the .for method' do
27
+ described_class.register 'abc', strategy
28
+ described_class.for(:abc).should == strategy
29
+ end
30
+ end
31
+
32
+
33
+ context 'when mixing into a class' do
34
+ let(:klass) { Class.new { include described_class } }
35
+
36
+ it 'is initialized with the code to test, and stores it' do
37
+ klass.new("abc").code_to_test.should == "abc"
38
+ end
39
+
40
+ it 'raises "unimplemented" when #pass? is invoked -- you should overwrite this method' do
41
+ expect { klass.new('').pass? }.to raise_error "unimplemented"
42
+ end
43
+
44
+ it 'raises "unimplemented" when #failure_message is invoked -- you should overwrite this method' do
45
+ expect { klass.new('').failure_message }.to raise_error "unimplemented"
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ class MountainBerryFields
4
+ describe Test do
5
+ let(:name) { 'Some name' }
6
+ let(:code) { 'Some code' }
7
+ let(:strategy_name) { :always_pass }
8
+ let(:test) { described_class.new name, code: code, with: strategy_name }
9
+
10
+ context 'the :strategy option' do
11
+ it 'tells it the name of its strategy' do
12
+ test.strategy.should == strategy_name
13
+ end
14
+ end
15
+
16
+ context 'the :code option' do
17
+ it 'provides the code that it is testing' do
18
+ test.code.should == code
19
+ end
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mountain_berry_fields
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Cheek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: erubis
16
+ requirement: &70327682095500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70327682095500
25
+ - !ruby/object:Gem::Dependency
26
+ name: deject
27
+ requirement: &70327682094500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.2.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70327682094500
36
+ - !ruby/object:Gem::Dependency
37
+ name: mountain_berry_fields-magic_comments
38
+ requirement: &70327682093580 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70327682093580
47
+ - !ruby/object:Gem::Dependency
48
+ name: mountain_berry_fields-rspec
49
+ requirement: &70327682092780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70327682092780
58
+ - !ruby/object:Gem::Dependency
59
+ name: surrogate
60
+ requirement: &70327682092320 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.5.1
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70327682092320
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70327682091860 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.10.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70327682091860
80
+ - !ruby/object:Gem::Dependency
81
+ name: cucumber
82
+ requirement: &70327682107760 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.2.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70327682107760
91
+ - !ruby/object:Gem::Dependency
92
+ name: simplecov
93
+ requirement: &70327682107280 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 0.6.4
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70327682107280
102
+ - !ruby/object:Gem::Dependency
103
+ name: rake
104
+ requirement: &70327682106900 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70327682106900
113
+ - !ruby/object:Gem::Dependency
114
+ name: pry
115
+ requirement: &70327682106440 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70327682106440
124
+ description: Test code samples embedded in files like readmes
125
+ email:
126
+ - josh.cheek@gmail.com
127
+ executables:
128
+ - mountain_berry_fields
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .simplecov
134
+ - Gemfile
135
+ - LICENSE
136
+ - Rakefile
137
+ - Readme.md
138
+ - Readme.md.mountain_berry_fields
139
+ - bin/mountain_berry_fields
140
+ - features/context_block.feature
141
+ - features/cwd_is_dir_of_mbf_file.feature
142
+ - features/rake_task.feature
143
+ - features/setup_block.feature
144
+ - features/step_definitions/steps.rb
145
+ - features/support/env.rb
146
+ - lib/mountain_berry_fields.rb
147
+ - lib/mountain_berry_fields/command_line_interaction.rb
148
+ - lib/mountain_berry_fields/evaluator.rb
149
+ - lib/mountain_berry_fields/parser.rb
150
+ - lib/mountain_berry_fields/rake_task.rb
151
+ - lib/mountain_berry_fields/test.rb
152
+ - lib/mountain_berry_fields/test/always_fail.rb
153
+ - lib/mountain_berry_fields/test/always_pass.rb
154
+ - lib/mountain_berry_fields/version.rb
155
+ - mountain_berry_fields.gemspec
156
+ - readme_helper.rb
157
+ - spec/command_line_interaction_spec.rb
158
+ - spec/evaluator_spec.rb
159
+ - spec/mock_substitutability_spec.rb
160
+ - spec/mountain_berry_fields_spec.rb
161
+ - spec/parser_spec.rb
162
+ - spec/ruby_syntax_checker_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/test/always_fail_spec.rb
165
+ - spec/test/always_pass_spec.rb
166
+ - spec/test/strategy_spec.rb
167
+ - spec/test/test_spec.rb
168
+ homepage: ''
169
+ licenses: []
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ! '>='
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 1.8.17
189
+ signing_key:
190
+ specification_version: 3
191
+ summary: Test code samples embedded in files like readmes
192
+ test_files:
193
+ - features/context_block.feature
194
+ - features/cwd_is_dir_of_mbf_file.feature
195
+ - features/rake_task.feature
196
+ - features/setup_block.feature
197
+ - features/step_definitions/steps.rb
198
+ - features/support/env.rb
199
+ - spec/command_line_interaction_spec.rb
200
+ - spec/evaluator_spec.rb
201
+ - spec/mock_substitutability_spec.rb
202
+ - spec/mountain_berry_fields_spec.rb
203
+ - spec/parser_spec.rb
204
+ - spec/ruby_syntax_checker_spec.rb
205
+ - spec/spec_helper.rb
206
+ - spec/test/always_fail_spec.rb
207
+ - spec/test/always_pass_spec.rb
208
+ - spec/test/strategy_spec.rb
209
+ - spec/test/test_spec.rb