diff options
| author | Markus Reiter | 2017-02-27 23:47:00 +0100 | 
|---|---|---|
| committer | Markus Reiter | 2017-02-27 23:52:20 +0100 | 
| commit | 8676960d09fda58ea36a34ce202ce30431474ac6 (patch) | |
| tree | f7b74d88736196deeb44e7c4f894deee0bc3ceae /Library/Homebrew/test/dev-cmd/audit_spec.rb | |
| parent | 14ae87d5c907165dcce7554edaf0c82ec89c2881 (diff) | |
| download | brew-8676960d09fda58ea36a34ce202ce30431474ac6.tar.bz2 | |
Convert FormulaText test to spec.
Diffstat (limited to 'Library/Homebrew/test/dev-cmd/audit_spec.rb')
| -rw-r--r-- | Library/Homebrew/test/dev-cmd/audit_spec.rb | 61 | 
1 files changed, 61 insertions, 0 deletions
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  | 
