From c55a9b17518a813550a615230c69a683d4f47cc0 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Fri, 12 Apr 2013 22:27:22 -0700 Subject: [PATCH] Initial commit; RSpec works --- .gitignore | 17 +++++++++++++++++ .rspec | 2 ++ .travis.yml | 6 ++++++ Gemfile | 4 ++++ LICENSE.txt | 22 ++++++++++++++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ Rakefile | 29 +++++++++++++++++++++++++++++ integration/rspec.rb | 29 +++++++++++++++++++++++++++++ lib/should_not.rb | 5 +++++ lib/should_not/rspec.rb | 11 +++++++++++ lib/should_not/version.rb | 3 +++ should_not.gemspec | 24 ++++++++++++++++++++++++ spec/should_not_spec.rb | 8 ++++++++ spec/spec_helper.rb | 1 + 14 files changed, 194 insertions(+) create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 .travis.yml create mode 100644 Gemfile create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 Rakefile create mode 100644 integration/rspec.rb create mode 100644 lib/should_not.rb create mode 100644 lib/should_not/rspec.rb create mode 100644 lib/should_not/version.rb create mode 100644 should_not.gemspec create mode 100644 spec/should_not_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d87d4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +*.gem +*.rbc +.bundle +.config +.yardoc +Gemfile.lock +InstalledFiles +_yardoc +coverage +doc/ +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..8c18f1a --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--format documentation +--color diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..967ba1e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: ruby +rvm: + - "1.9.3" + - "2.0.0" +notifications: + email: false diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..9a02524 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +# Specify your gem's dependencies in should_not.gemspec +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..922dae5 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ +Copyright (c) 2013 Mark Rushakoff + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad79739 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# should_not + +You `should_not` start your specs with the string `"should"`. + +## Installation + +Add this line to your application's Gemfile: + + gem 'should_not' + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install should_not + +## Usage + +### RSpec + +In `spec_helper.rb`, add the line: + + require 'should_not/rspec' + +## Contributing + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. Push to the branch (`git push origin my-new-feature`) +5. Create new Pull Request diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..c15a69a --- /dev/null +++ b/Rakefile @@ -0,0 +1,29 @@ +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' +require 'stringio' + +RSpec::Core::RakeTask.new(:spec) + +task :default => :spec + +task :rspec do + require 'rspec/core' + err = StringIO.new + out = StringIO.new + RSpec::Core::Runner.run([integration_file('rspec')], err, out) + + assert_contains!(out.string, '6 examples, 2 failures') +end + +INTEGRATION_DIR = File.expand_path(File.join(File.dirname(__FILE__), 'integration')) + +def integration_file(filename) + filename << '.rb' unless filename.end_with?('.rb') + File.join(INTEGRATION_DIR, filename) +end + +def assert_contains!(actual, expected) + unless actual.include?(expected) + abort("Expected (< true do + 1.should == 1 + end + + describe 'a nested context' do + it 'should also fail when the string starts with should' do + 1.should == 1 + end + + it 'can also pass a normal test' do + 1.should == 1 + end + + it 'should also allow should on an "it" through metadata', :should => true do + 1.should == 1 + end + end +end diff --git a/lib/should_not.rb b/lib/should_not.rb new file mode 100644 index 0000000..bbbd691 --- /dev/null +++ b/lib/should_not.rb @@ -0,0 +1,5 @@ +require "should_not/version" + +module ShouldNot + # Your code goes here... +end diff --git a/lib/should_not/rspec.rb b/lib/should_not/rspec.rb new file mode 100644 index 0000000..168de3b --- /dev/null +++ b/lib/should_not/rspec.rb @@ -0,0 +1,11 @@ +require 'rspec/core' + +RSpec.configure do |config| + STARTS_WITH_SHOULD = /\Ashould\s/.freeze + config.before(:each) do + next if example.metadata[:should] == true + # Not sure that last is correct here -- is the array ever larger than one element? + description = example.metadata[:description_args].last.to_s + fail("You should_not start an example with should!") if description.match(STARTS_WITH_SHOULD) + end +end diff --git a/lib/should_not/version.rb b/lib/should_not/version.rb new file mode 100644 index 0000000..1996d10 --- /dev/null +++ b/lib/should_not/version.rb @@ -0,0 +1,3 @@ +module ShouldNot + VERSION = "0.0.1" +end diff --git a/should_not.gemspec b/should_not.gemspec new file mode 100644 index 0000000..c93dcbd --- /dev/null +++ b/should_not.gemspec @@ -0,0 +1,24 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'should_not/version' + +Gem::Specification.new do |spec| + spec.name = "should_not" + spec.version = ShouldNot::VERSION + spec.authors = ["Mark Rushakoff"] + spec.email = ["mark.rushakoff@gmail.com"] + spec.description = %q{You should_not start your specs with the string "should".} + spec.summary = %q{Fail specs that start with should.} + spec.homepage = "https://github.com/mark-rushakoff/should_not" + spec.license = "MIT" + + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.require_paths = ["lib"] + + spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "rake" + spec.add_development_dependency "rspec" +end diff --git a/spec/should_not_spec.rb b/spec/should_not_spec.rb new file mode 100644 index 0000000..e4156ee --- /dev/null +++ b/spec/should_not_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' +require 'should_not' + +describe ShouldNot do + it 'should have a version number' do + ShouldNot::VERSION.should_not be_nil + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..f6228ad --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1 @@ +$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)