mountain_berry_fields-rspec 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.simplecov +5 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/Rakefile +19 -0
- data/Readme.md +7 -0
- data/features/step_definitions/steps.rb +46 -0
- data/features/support/env.rb +73 -0
- data/features/test_with_rspec.feature +88 -0
- data/lib/mountain_berry_fields/test/rspec.rb +77 -0
- data/lib/mountain_berry_fields/test/rspec_formatter.rb +16 -0
- data/mountain_berry_fields-rspec.gemspec +24 -0
- data/spec/spec_helper.rb +57 -0
- data/spec/test/rspec_spec.rb +85 -0
- metadata +142 -0
data/.gitignore
ADDED
data/.simplecov
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Josh Cheek
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
|
5
|
+
task :rspec do
|
6
|
+
require 'rspec'
|
7
|
+
Dir.glob("spec/**/*_spec.rb").each { |filename| require File.expand_path filename }
|
8
|
+
RSpec::Core::Runner.run []
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'cucumber/rake/task'
|
12
|
+
default_cucumber_opts = "features --format pretty --tags ~@not-implemented"
|
13
|
+
Cucumber::Rake::Task.new(:cucumber) { |t| t.cucumber_opts = default_cucumber_opts + " --tags ~@wip" }
|
14
|
+
Cucumber::Rake::Task.new('cucumber:wip') { |t| t.cucumber_opts = default_cucumber_opts + " --tags @wip" }
|
15
|
+
|
16
|
+
|
17
|
+
task default: [:rspec, :cucumber]
|
18
|
+
|
19
|
+
|
data/Readme.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# RSpec strategy for Mountain Berry Fields
|
2
|
+
|
3
|
+
As this is an official plugin, it is documented as part of the main [MountainBerryFields](https://github.com/JoshCheek/mountain_berry_fields) code.
|
4
|
+
|
5
|
+
If you have it installed (`gem install mountain_berry_fields-rspec`), then it will be automatically loaded by MountainBerryFields, no further steps are necessary.
|
6
|
+
If you are using Bundler, make sure it is in your Gemfile. If using Rubygems, set it as a development dependency
|
7
|
+
([example](https://github.com/JoshCheek/mountain_berry_fields/blob/be751536c8b0f94c84b09167fa83616b94b13b12/mountain_berry_fields.gemspec#L22)).
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Given 'the file "$filename":' do |filename, body|
|
2
|
+
in_proving_grounds do
|
3
|
+
ensure_dir File.dirname filename
|
4
|
+
File.write filename, interpret_curlies(body)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
When 'I run "$command"' do |command|
|
9
|
+
in_proving_grounds { cmdline command }
|
10
|
+
end
|
11
|
+
|
12
|
+
Then /^it exits with a status of (\d+)$/ do |status|
|
13
|
+
last_cmdline.exitstatus.should eq(status.to_i), "Expected #{status}, got #{last_cmdline.exitstatus}. STDERR: #{last_cmdline.stderr}"
|
14
|
+
end
|
15
|
+
|
16
|
+
Then /^it exits with a status of (\d+), and a stderr of:$/ do |status, stderr|
|
17
|
+
last_cmdline.exitstatus.should == status.to_i
|
18
|
+
last_cmdline.stderr.chomp.should == interpret_curlies(stderr).chomp
|
19
|
+
end
|
20
|
+
|
21
|
+
Then /^it prints nothing to (stdout|stderr)$/ do |descriptor|
|
22
|
+
last_cmdline.send(descriptor).should == ''
|
23
|
+
end
|
24
|
+
|
25
|
+
Then 'I see the file "$filename"' do |filename|
|
26
|
+
in_proving_grounds { File.exist?(filename).should be_true }
|
27
|
+
end
|
28
|
+
|
29
|
+
Then 'I see the file "$filename":' do |filename, body|
|
30
|
+
in_proving_grounds do
|
31
|
+
File.exist?(filename).should be_true, "#{filename} doesn't exist"
|
32
|
+
|
33
|
+
body && strip_trailing_whitespace(File.read(filename)).should ==
|
34
|
+
strip_trailing_whitespace(body)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Then 'I do not see the file "$filename"' do |filename|
|
39
|
+
in_proving_grounds { File.exist?(filename).should be_false }
|
40
|
+
end
|
41
|
+
|
42
|
+
And 'I pry' do
|
43
|
+
require 'pry'
|
44
|
+
binding.pry
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module ProvingGrounds
|
3
|
+
def proving_grounds_dir
|
4
|
+
File.expand_path "../../proving_grounds", __FILE__
|
5
|
+
end
|
6
|
+
|
7
|
+
def in_proving_grounds(&block)
|
8
|
+
make_proving_grounds
|
9
|
+
FileUtils.cd(proving_grounds_dir) { return block.call }
|
10
|
+
end
|
11
|
+
|
12
|
+
def make_proving_grounds
|
13
|
+
FileUtils.mkdir_p proving_grounds_dir
|
14
|
+
end
|
15
|
+
|
16
|
+
def remove_proving_grounds
|
17
|
+
FileUtils.rm_r proving_grounds_dir
|
18
|
+
end
|
19
|
+
|
20
|
+
def ensure_dir(dirname)
|
21
|
+
FileUtils.mkdir_p dirname
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
module Helpers
|
27
|
+
def interpret_curlies(string)
|
28
|
+
string.gsub /{{.*?}}/ do |code|
|
29
|
+
code.sub! /^{{/, ''
|
30
|
+
code.sub! /}}$/, ''
|
31
|
+
eval code
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def strip_trailing_whitespace(text)
|
36
|
+
text.gsub /\s+$/, ''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
require 'open3'
|
41
|
+
class CommandLine
|
42
|
+
module CukeHelpers
|
43
|
+
def cmdline(command, options={})
|
44
|
+
@last_cmdline = CommandLine.new(command, options)
|
45
|
+
@last_cmdline.execute
|
46
|
+
@last_cmdline
|
47
|
+
end
|
48
|
+
|
49
|
+
def last_cmdline
|
50
|
+
@last_cmdline
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :command, :options, :stderr, :stdout
|
55
|
+
|
56
|
+
def initialize(command, options={})
|
57
|
+
@command, @options = command, options
|
58
|
+
end
|
59
|
+
|
60
|
+
def execute
|
61
|
+
@stdout, @stderr, @status = Open3.capture3(command, @options)
|
62
|
+
end
|
63
|
+
|
64
|
+
def exitstatus
|
65
|
+
@status.exitstatus
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
ENV['RUBYLIB'] = "#{File.expand_path "../../../bin", __FILE__}:#{ENV['RUBYLIB']}"
|
70
|
+
World ProvingGrounds
|
71
|
+
World CommandLine::CukeHelpers
|
72
|
+
World Helpers
|
73
|
+
After { remove_proving_grounds }
|
@@ -0,0 +1,88 @@
|
|
1
|
+
Feature: Testing with :rspec
|
2
|
+
|
3
|
+
Scenario: Passing RSpec
|
4
|
+
Given the file "Readme.mountain_berry_fields.md":
|
5
|
+
"""
|
6
|
+
# Whatever
|
7
|
+
|
8
|
+
|
9
|
+
<% test 'My RSpec example', with: :rspec do %>
|
10
|
+
describe 'an example' do
|
11
|
+
it('passes') { true.should be_true }
|
12
|
+
end
|
13
|
+
<% end %>
|
14
|
+
|
15
|
+
ya see?
|
16
|
+
"""
|
17
|
+
When I run "mountain_berry_fields Readme.mountain_berry_fields.md"
|
18
|
+
Then it prints nothing to stdout
|
19
|
+
And it prints nothing to stderr
|
20
|
+
And it exits with a status of 0
|
21
|
+
And I see the file "Readme.md":
|
22
|
+
"""
|
23
|
+
# Whatever
|
24
|
+
|
25
|
+
|
26
|
+
describe 'an example' do
|
27
|
+
it('passes') { true.should be_true }
|
28
|
+
end
|
29
|
+
|
30
|
+
ya see?
|
31
|
+
"""
|
32
|
+
|
33
|
+
Scenario: Failing RSpec
|
34
|
+
Given the file "Readme.mountain_berry_fields.md":
|
35
|
+
"""
|
36
|
+
# Whatever
|
37
|
+
|
38
|
+
|
39
|
+
<% test 'My RSpec example', with: :rspec do %>
|
40
|
+
describe 'an example' do
|
41
|
+
it('fails 1') { true.should be_false, 'failure message 1' }
|
42
|
+
it('fails 2') { true.should be_false, 'failure message 2' }
|
43
|
+
end
|
44
|
+
<% end %>
|
45
|
+
|
46
|
+
ya see?
|
47
|
+
"""
|
48
|
+
When I run "mountain_berry_fields Readme.mountain_berry_fields.md"
|
49
|
+
Then it exits with a status of 1, and a stderr of:
|
50
|
+
"""
|
51
|
+
FAILURE: My RSpec example
|
52
|
+
an example fails 1:
|
53
|
+
failure message 1
|
54
|
+
|
55
|
+
backtrace:
|
56
|
+
/spec.rb:2:in `block (2 levels) in <top (required)>'
|
57
|
+
"""
|
58
|
+
And I do not see the file "Readme.md"
|
59
|
+
|
60
|
+
|
61
|
+
Scenario: Invalid example
|
62
|
+
Given the file "Readme.mountain_berry_fields.md":
|
63
|
+
"""
|
64
|
+
# Whatever
|
65
|
+
|
66
|
+
|
67
|
+
<% test 'My RSpec example', with: :rspec do %>
|
68
|
+
describe 'an example' do
|
69
|
+
it('is invalid syntax') { }}}}
|
70
|
+
end
|
71
|
+
<% end %>
|
72
|
+
|
73
|
+
ya see?
|
74
|
+
"""
|
75
|
+
When I run "mountain_berry_fields Readme.mountain_berry_fields.md"
|
76
|
+
Then it exits with a status of 1, and a stderr of:
|
77
|
+
"""
|
78
|
+
FAILURE: My RSpec example
|
79
|
+
-:2: syntax error, unexpected '}', expecting keyword_end
|
80
|
+
it('is invalid syntax') { }}}}
|
81
|
+
^
|
82
|
+
|
83
|
+
original file:
|
84
|
+
describe 'an example' do
|
85
|
+
it('is invalid syntax') { }}}}
|
86
|
+
end
|
87
|
+
"""
|
88
|
+
And I do not see the file "Readme.md"
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'json'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
class MountainBerryFields
|
6
|
+
class Test
|
7
|
+
|
8
|
+
class RSpec
|
9
|
+
Deject self
|
10
|
+
dependency(:file_class) { File }
|
11
|
+
dependency(:dir_class) { Dir }
|
12
|
+
dependency(:open3_class) { Open3 }
|
13
|
+
dependency(:syntax_checker_class) { RubySyntaxChecker }
|
14
|
+
|
15
|
+
def syntax_checker
|
16
|
+
@syntax_checker ||= syntax_checker_class.new code_to_test
|
17
|
+
end
|
18
|
+
|
19
|
+
Strategy.register :rspec, self
|
20
|
+
|
21
|
+
include Strategy
|
22
|
+
|
23
|
+
def pass?
|
24
|
+
@passed ||= syntax_checker.valid? && begin
|
25
|
+
dir_class.mktmpdir 'mountain_berry_fields_rspec' do |dir|
|
26
|
+
@tempdir_name = dir
|
27
|
+
file_class.write "#{dir}/spec.rb", @code_to_test
|
28
|
+
@output, @error, status = open3_class.capture3 "rspec '#{dir}/spec.rb' " \
|
29
|
+
"-r '#{formatter_filename}' " \
|
30
|
+
"-f MountainBerryFields::Test::RSpec::Formatter " \
|
31
|
+
"--fail-fast"
|
32
|
+
status.success?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@passed
|
36
|
+
end
|
37
|
+
|
38
|
+
def syntax_error_message
|
39
|
+
return if syntax_checker.valid?
|
40
|
+
syntax_checker.invalid_message
|
41
|
+
end
|
42
|
+
|
43
|
+
def failure_message
|
44
|
+
syntax_error_message ||
|
45
|
+
"#{spec_failure_description.chomp}:\n" \
|
46
|
+
" #{spec_failure_message.chomp}\n" \
|
47
|
+
"\n" \
|
48
|
+
"backtrace:\n" \
|
49
|
+
" #{spec_failure_backtrace.join "\n "}\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def spec_failure_description
|
55
|
+
result['full_description']
|
56
|
+
end
|
57
|
+
|
58
|
+
def spec_failure_message
|
59
|
+
result['message']
|
60
|
+
end
|
61
|
+
|
62
|
+
def spec_failure_backtrace
|
63
|
+
result['backtrace'].map { |line| line.gsub @tempdir_name, '' }
|
64
|
+
end
|
65
|
+
|
66
|
+
def result
|
67
|
+
@result ||= JSON.parse @output
|
68
|
+
end
|
69
|
+
|
70
|
+
def formatter_filename
|
71
|
+
File.expand_path "../rspec_formatter.rb", __FILE__
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rspec/core/formatters/base_formatter'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class MountainBerryFields
|
5
|
+
class Test
|
6
|
+
class RSpec
|
7
|
+
class Formatter < ::RSpec::Core::Formatters::BaseFormatter
|
8
|
+
def example_failed(example)
|
9
|
+
print JSON.dump 'full_description' => example.full_description,
|
10
|
+
'message' => example.exception.message,
|
11
|
+
'backtrace' => format_backtrace(example.exception.backtrace, example)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.authors = ["Josh Cheek"]
|
4
|
+
gem.email = ["josh.cheek@gmail.com"]
|
5
|
+
gem.description = %q{When testing embedded code examples with MountainBerryFields, you may wish to use RSpec. This enables that integration}
|
6
|
+
gem.summary = %q{MountainBerryFields strategy for RSpec}
|
7
|
+
gem.homepage = "https://github.com/JoshCheek/mountain_berry_fields-rspec"
|
8
|
+
|
9
|
+
gem.files = `git ls-files`.split($\)
|
10
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
|
+
gem.name = "mountain_berry_fields-rspec"
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.version = '1.0.0'
|
15
|
+
|
16
|
+
gem.add_runtime_dependency 'deject', '~> 0.2.2'
|
17
|
+
gem.add_development_dependency 'rspec', '~> 2.10.0' # this might be overly strict, maybe do research and see how far back we can go
|
18
|
+
|
19
|
+
gem.add_development_dependency 'mountain_berry_fields', '~> 1.0.0'
|
20
|
+
gem.add_development_dependency 'surrogate', '~> 0.5.1'
|
21
|
+
gem.add_development_dependency 'cucumber', '~> 1.2.0'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
gem.add_development_dependency 'pry'
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'surrogate/rspec'
|
2
|
+
require 'mountain_berry_fields'
|
3
|
+
require 'mountain_berry_fields/test/rspec'
|
4
|
+
|
5
|
+
RSpec::Matchers.define :pass do
|
6
|
+
match { |matcher| matcher.pass? }
|
7
|
+
end
|
8
|
+
|
9
|
+
module Mock
|
10
|
+
class SyntaxChecker
|
11
|
+
Surrogate.endow self
|
12
|
+
define(:initialize) { |syntax| }
|
13
|
+
define(:valid?) { true }
|
14
|
+
define(:invalid_message) { "shit ain't valid" }
|
15
|
+
end
|
16
|
+
|
17
|
+
class Dir
|
18
|
+
Surrogate.endow self do
|
19
|
+
define(:chdir) { |dir, &block| block.call }
|
20
|
+
define(:mktmpdir) { |prefix, &block| block.call }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class File
|
25
|
+
Surrogate.endow self do
|
26
|
+
define(:exist?) { true }
|
27
|
+
define(:write) { true }
|
28
|
+
define(:read) { "file contents" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Open3
|
33
|
+
Surrogate.endow self do
|
34
|
+
define(:capture3) { |invocation| ["stdout", "stderr", @exitstatus||Process::Status.new] }
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def self.exit_with_failure!
|
39
|
+
@exitstatus = Process::Status.new.will_have_success? false
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.exit_with_success!
|
44
|
+
@exitstatus = Process::Status.new.will_have_success? true
|
45
|
+
self
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Process
|
50
|
+
class Status
|
51
|
+
Surrogate.endow self
|
52
|
+
define(:success?) { true }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
MountainBerryFields::Test::RSpec.override(:syntax_checker_class) { Mock::SyntaxChecker }
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MountainBerryFields::Test::RSpec do
|
4
|
+
it 'is registered it the strategy list under :rspec' do
|
5
|
+
MountainBerryFields::Test::Strategy.for(:rspec).should == described_class
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:passing_spec) { <<-EOF.gsub /^ {4}/, '' }
|
9
|
+
describe 'an example' do
|
10
|
+
it('passes') { true.should be_true }
|
11
|
+
end
|
12
|
+
EOF
|
13
|
+
|
14
|
+
let(:failing_spec) { <<-EOF.gsub /^ {4}/, '' }
|
15
|
+
describe 'an example' do
|
16
|
+
it('fails') { true.should be_false, 'the message' }
|
17
|
+
end
|
18
|
+
EOF
|
19
|
+
|
20
|
+
let(:spec_with_two_failures) { <<-EOF.gsub /^ {4}/, '' }
|
21
|
+
describe 'an example' do
|
22
|
+
it('fails 1') { true.should be_false, 'failure message 1' }
|
23
|
+
it('fails 2') { true.should be_false, 'failure message 2' }
|
24
|
+
end
|
25
|
+
EOF
|
26
|
+
|
27
|
+
let(:file_class) { Mock::File.clone }
|
28
|
+
let(:dir_class) { Mock::Dir.clone }
|
29
|
+
let(:open3_class) { Mock::Open3.clone }
|
30
|
+
let(:the_spec) { passing_spec }
|
31
|
+
|
32
|
+
it 'checks input syntax first' do
|
33
|
+
rspec = described_class.new the_spec
|
34
|
+
syntax_checker = rspec.syntax_checker
|
35
|
+
syntax_checker.was initialized_with the_spec
|
36
|
+
syntax_checker.will_have_valid? false # rename to valid_syntax
|
37
|
+
syntax_checker.will_have_invalid_message "you call that code?"
|
38
|
+
rspec.should_not pass
|
39
|
+
rspec.failure_message.should == "you call that code?"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'writes the file to a temp dir' do
|
43
|
+
rspec = described_class.new(the_spec).with_dependencies(dir_class: dir_class, file_class: file_class, open3_class: open3_class)
|
44
|
+
dir_class.will_mktmpdir true
|
45
|
+
rspec.pass?
|
46
|
+
rspec.dir_class.was told_to(:mktmpdir).with('mountain_berry_fields_rspec') { |block|
|
47
|
+
block.call_with '/temp_dir'
|
48
|
+
block.before { file_class.was_not told_to :write }
|
49
|
+
block.after { file_class.was told_to(:write).with("/temp_dir/spec.rb", the_spec) }
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'invokes rspec against the temp dir' do
|
54
|
+
rspec = described_class.new(the_spec).with_dependencies(dir_class: dir_class, file_class: file_class, open3_class: open3_class)
|
55
|
+
dir_class.will_mktmpdir true
|
56
|
+
rspec.pass?
|
57
|
+
rspec.dir_class.was told_to(:mktmpdir).with('mountain_berry_fields_rspec') { |block|
|
58
|
+
block.call_with '/temp_dir'
|
59
|
+
block.before { open3_class.was_not told_to :capture3 }
|
60
|
+
block.after { open3_class.was told_to :capture3 } # not testing string directly, will let cukes verify it comes out right
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'passes when rspec executes successfully' do
|
65
|
+
open3_class = Mock::Open3.clone.exit_with_success!
|
66
|
+
rspec = described_class.new(the_spec).with_dependencies(dir_class: dir_class, file_class: file_class, open3_class: open3_class)
|
67
|
+
rspec.should pass
|
68
|
+
|
69
|
+
open3_class = Mock::Open3.clone.exit_with_failure!
|
70
|
+
rspec = described_class.new(the_spec).with_dependencies(dir_class: dir_class, file_class: file_class, open3_class: open3_class)
|
71
|
+
rspec.should_not pass
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'pulls its failure message from the JSON output of the results, showing the description, message, and backtrace without the temp dir' do
|
75
|
+
temp_dir = 'some_temp_dir'
|
76
|
+
open3_class.will_capture3 [%'{"full_description":"THE DESCRIPTION","message":"THE MESSAGE","backtrace":["#{temp_dir}/THE BACKTRACE"]}', '', Mock::Process::Status.new]
|
77
|
+
rspec = described_class.new(the_spec).with_dependencies(dir_class: dir_class, file_class: file_class, open3_class: open3_class)
|
78
|
+
rspec.pass?
|
79
|
+
dir_class.was told_to(:mktmpdir).with(anything) { |block| block.call_with temp_dir }
|
80
|
+
rspec.failure_message.should include 'THE DESCRIPTION'
|
81
|
+
rspec.failure_message.should include 'THE MESSAGE'
|
82
|
+
rspec.failure_message.should include 'THE BACKTRACE'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mountain_berry_fields-rspec
|
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: deject
|
16
|
+
requirement: &70101747405880 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.2.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70101747405880
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70101747403840 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.10.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70101747403840
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mountain_berry_fields
|
38
|
+
requirement: &70101747402400 !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: *70101747402400
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: surrogate
|
49
|
+
requirement: &70101747417580 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.1
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70101747417580
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: cucumber
|
60
|
+
requirement: &70101747416660 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.2.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70101747416660
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: &70101747415900 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70101747415900
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: pry
|
82
|
+
requirement: &70101747414980 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70101747414980
|
91
|
+
description: When testing embedded code examples with MountainBerryFields, you may
|
92
|
+
wish to use RSpec. This enables that integration
|
93
|
+
email:
|
94
|
+
- josh.cheek@gmail.com
|
95
|
+
executables: []
|
96
|
+
extensions: []
|
97
|
+
extra_rdoc_files: []
|
98
|
+
files:
|
99
|
+
- .gitignore
|
100
|
+
- .simplecov
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE
|
103
|
+
- Rakefile
|
104
|
+
- Readme.md
|
105
|
+
- features/step_definitions/steps.rb
|
106
|
+
- features/support/env.rb
|
107
|
+
- features/test_with_rspec.feature
|
108
|
+
- lib/mountain_berry_fields/test/rspec.rb
|
109
|
+
- lib/mountain_berry_fields/test/rspec_formatter.rb
|
110
|
+
- mountain_berry_fields-rspec.gemspec
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/test/rspec_spec.rb
|
113
|
+
homepage: https://github.com/JoshCheek/mountain_berry_fields-rspec
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.17
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: MountainBerryFields strategy for RSpec
|
137
|
+
test_files:
|
138
|
+
- features/step_definitions/steps.rb
|
139
|
+
- features/support/env.rb
|
140
|
+
- features/test_with_rspec.feature
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/test/rspec_spec.rb
|