diff options
| author | mansimarkaur | 2017-07-27 17:47:28 +0530 |
|---|---|---|
| committer | mansimarkaur | 2017-08-29 16:24:19 +0530 |
| commit | 2660f5ae3ea5e0ce466e6f9b3b736a12ad3a341a (patch) | |
| tree | 746242226b511a1566f00e892a43cae8d4ffa81e /Library | |
| parent | a4d4da64aab707e2f39fcc32fec6418cc39e8010 (diff) | |
| download | brew-2660f5ae3ea5e0ce466e6f9b3b736a12ad3a341a.tar.bz2 | |
Added tests for report and report_event
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/test/utils/analytics_spec.rb | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index cee09e286..96a9a4f7f 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -1,19 +1,27 @@ require "utils/analytics" +require "formula_installer" describe Utils::Analytics do describe "::os_prefix_ci" do context "when anonymous_os_prefix_ci is not set" do + before(:each) do + if described_class.instance_variable_defined?(:@anonymous_os_prefix_ci) + described_class.send(:remove_instance_variable, :@anonymous_os_prefix_ci) + end + end + it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do + stub_const("HOMEBREW_PREFIX", "blah") expect(described_class.os_prefix_ci).to include("#{OS_VERSION}, non-/usr/local") end it "includes CI when ENV['CI'] is set" do - allow(ENV).to receive(:[]).with("CI").and_return("true") + ENV["CI"] = "true" expect(described_class.os_prefix_ci).to include("CI") end it "does not include prefix when HOMEBREW_PREFIX is usr/local" do - allow(HOMEBREW_PREFIX).to receive(:to_s).and_return("/usr/local") + stub_const("HOMEBREW_PREFIX", "/usr/local") expect(described_class.os_prefix_ci).not_to include("non-/usr/local") end end @@ -28,7 +36,39 @@ describe Utils::Analytics do end end - describe "::" do - + describe "::report_event" do + let(:f) { formula { url "foo-1.0" } } + let(:options) { FormulaInstaller.new(f).display_options(f) } + let(:action) { "#{f.full_name} #{options}".strip } + + context "when ENV vars is set" do + it "returns nil when HOMEBREW_NO_ANALYTICS is true" do + ENV["HOMEBREW_NO_ANALYTICS"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_NO_ANALYTICS_THIS_RUN is true" do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + + it "returns nil when HOMEBREW_ANALYTICS_DEBUG is true" do + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" + expect(described_class.report_event("install", action)).to be_nil + end + end + + context "when ENV vars are nil" do + before do + ENV["HOMEBREW_NO_ANALYTICS"] = nil + ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = nil + end + + it "returns nil when HOMEBREW_ANALYTICS_DEBUG is not set" do + expect(described_class.report_event("install", action)).to be_an_instance_of(Thread) + end + end end -end
\ No newline at end of file +end |
