aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-02-28 10:33:57 +0100
committerGitHub2017-02-28 10:33:57 +0100
commit5498f5369c22f1550a105050f2cb3bc12c83d598 (patch)
tree5c8247b79e8e16546d23ae37dcf372363edb5ad2 /Library
parenta912c60d9a130da02797d603dd64db8ed0a3dc19 (diff)
parent8676960d09fda58ea36a34ce202ce30431474ac6 (diff)
downloadbrew-5498f5369c22f1550a105050f2cb3bc12c83d598.tar.bz2
Merge pull request #2228 from reitermarkus/spec-audit
Convert FormulaText test to spec.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/audit_test.rb49
-rw-r--r--Library/Homebrew/test/dev-cmd/audit_spec.rb61
2 files changed, 61 insertions, 49 deletions
diff --git a/Library/Homebrew/test/audit_test.rb b/Library/Homebrew/test/audit_test.rb
index 66e5af567..b8f01602c 100644
--- a/Library/Homebrew/test/audit_test.rb
+++ b/Library/Homebrew/test/audit_test.rb
@@ -4,55 +4,6 @@ require "pathname"
require "formulary"
require "dev-cmd/audit"
-class FormulaTextTests < Homebrew::TestCase
- def setup
- super
- @dir = mktmpdir
- end
-
- def formula_text(name, body = nil, options = {})
- path = Pathname.new "#{@dir}/#{name}.rb"
- path.open("w") do |f|
- f.write <<-EOS.undent
- class #{Formulary.class_s(name)} < Formula
- #{body}
- end
- #{options[:patch]}
- EOS
- end
- FormulaText.new path
- end
-
- def test_simple_valid_formula
- ft = formula_text "valid", 'url "http://www.example.com/valid-1.0.tar.gz"'
-
- refute ft.data?, "The formula should not have DATA"
- refute ft.end?, "The formula should not have __END__"
- assert ft.trailing_newline?, "The formula should have a trailing newline"
-
- assert ft =~ /\burl\b/, "The formula should match 'url'"
- assert_nil ft.line_number(/desc/), "The formula should not match 'desc'"
- assert_equal 2, ft.line_number(/\burl\b/)
- assert ft.include?("Valid"), "The formula should include \"Valid\""
- end
-
- def test_trailing_newline
- ft = formula_text "newline"
- assert ft.trailing_newline?, "The formula must have a trailing newline"
- end
-
- def test_has_data
- ft = formula_text "data", "patch :DATA"
- assert ft.data?, "The formula must have DATA"
- end
-
- def test_has_end
- ft = formula_text "end", "", patch: "__END__\na patch here"
- assert ft.end?, "The formula must have __END__"
- assert_equal "class End < Formula\n \nend", ft.without_patch
- end
-end
-
class FormulaAuditorTests < Homebrew::TestCase
def setup
super
diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb
new file mode 100644
index 000000000..397e6912d
--- /dev/null
+++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb
@@ -0,0 +1,61 @@
+require "dev-cmd/audit"
+require "formulary"
+
+RSpec::Matchers.alias_matcher :have_data, :be_data
+RSpec::Matchers.alias_matcher :have_end, :be_end
+RSpec::Matchers.alias_matcher :have_trailing_newline, :be_trailing_newline
+
+describe FormulaText do
+ let(:dir) { @dir = Pathname.new(Dir.mktmpdir) }
+
+ after(:each) do
+ dir.rmtree unless @dir.nil?
+ end
+
+ def formula_text(name, body = nil, options = {})
+ path = dir/"#{name}.rb"
+
+ path.write <<-EOS.undent
+ class #{Formulary.class_s(name)} < Formula
+ #{body}
+ end
+ #{options[:patch]}
+ EOS
+
+ described_class.new(path)
+ end
+
+ specify "simple valid Formula" do
+ ft = formula_text "valid", <<-EOS.undent
+ url "http://www.example.com/valid-1.0.tar.gz"
+ EOS
+
+ expect(ft).not_to have_data
+ expect(ft).not_to have_end
+ expect(ft).to have_trailing_newline
+
+ expect(ft =~ /\burl\b/).to be_truthy
+ expect(ft.line_number(/desc/)).to be nil
+ expect(ft.line_number(/\burl\b/)).to eq(2)
+ expect(ft).to include("Valid")
+ end
+
+ specify "#trailing_newline?" do
+ ft = formula_text "newline"
+ expect(ft).to have_trailing_newline
+ end
+
+ specify "#data?" do
+ ft = formula_text "data", <<-EOS.undent
+ patch :DATA
+ EOS
+
+ expect(ft).to have_data
+ end
+
+ specify "#end?" do
+ ft = formula_text "end", "", patch: "__END__\na patch here"
+ expect(ft).to have_end
+ expect(ft.without_patch).to eq("class End < Formula\n \nend")
+ end
+end