Permalink
Browse files

Move port/jasmine_host to config

- Allows us to remove unit tests that were mocking the object they are testing
- Also remove usages of eq matcher, not avail. in older versions of
  rspec.
- Fixes Rails 2.x builds
- Config cohesiveness is bad and getting worse. :(
  • Loading branch information...
ragaskar authored and Rajan Agaskar committed Oct 2, 2012
1 parent f8d1c44 commit 977634f200a912cef0e80cf155b7e3e259b43615
Showing with 55 additions and 48 deletions.
  1. +8 −0 lib/jasmine/config.rb
  2. +4 −8 lib/jasmine/runner_config.rb
  3. +31 −0 spec/config_spec.rb
  4. +12 −40 spec/runner_config_spec.rb
View
@@ -102,6 +102,14 @@ def stylesheets
end
end
+ def jasmine_host
+ ENV["JASMINE_HOST"] || 'http://localhost'
+ end
+
+ def port
+ @port ||= ENV["JASMINE_PORT"] || Jasmine.find_unused_port
+ end
+
def jasmine_stylesheets
::Jasmine::Core.css_files.map {|f| "/__JASMINE_ROOT__/#{f}"}
end
@@ -48,16 +48,12 @@ def browser
ENV["JASMINE_BROWSER"] || 'firefox'
end
- def jasmine_server_url
- "#{jasmine_host}:#{port}/"
- end
-
- def jasmine_host
- ENV["JASMINE_HOST"] || 'http://localhost'
+ def port
+ @config.port
end
- def port
- @port ||= ENV["JASMINE_PORT"] || Jasmine.find_unused_port
+ def jasmine_server_url
+ "#{@config.jasmine_host}:#{@config.port}/"
end
def src_mapper=(context)
View
@@ -275,4 +275,35 @@
config.src_files.should == mapped_files
end
end
+
+ describe "jasmine_host" do
+ it "should default to localhost" do
+ Jasmine::Config.new.jasmine_host.should == 'http://localhost'
+ end
+
+ it "should use ENV['JASMINE_HOST'] if it exists" do
+ ENV.stub(:[], "JASMINE_HOST").and_return("foo")
+ Jasmine::Config.new.jasmine_host.should == 'foo'
+ end
+ end
+
+ describe "port" do
+ it "should find an unused port" do
+ Jasmine.should_receive(:find_unused_port).and_return('1234')
+ Jasmine::Config.new.port.should == '1234'
+ end
+
+ it "should use ENV['JASMINE_PORT'] if it exists" do
+ ENV.stub(:[], "JASMINE_PORT").and_return("foo")
+ Jasmine::Config.new.port.should == 'foo'
+ end
+
+ it "should cache port" do
+ config = Jasmine::Config.new
+ Jasmine.stub(:find_unused_port).and_return('1234')
+ config.port.should == '1234'
+ Jasmine.stub(:find_unused_port).and_return('4321')
+ config.port.should == '1234'
+ end
+ end
end
View
@@ -94,36 +94,6 @@
end
end
- describe "jasmine_host" do
- it "should default to localhost" do
- Jasmine::RunnerConfig.new.jasmine_host.should == 'http://localhost'
- end
-
- it "should use ENV['JASMINE_HOST'] if it exists" do
- ENV.stub(:[], "JASMINE_HOST").and_return("foo")
- Jasmine::RunnerConfig.new.jasmine_host.should == 'foo'
- end
- end
-
- describe "port" do
- it "should find an unused port" do
- Jasmine.should_receive(:find_unused_port).and_return('1234')
- Jasmine::RunnerConfig.new.port.should == '1234'
- end
-
- it "should use ENV['JASMINE_PORT'] if it exists" do
- ENV.stub(:[], "JASMINE_PORT").and_return("foo")
- Jasmine::RunnerConfig.new.port.should == 'foo'
- end
-
- it "should cache port" do
- config = Jasmine::RunnerConfig.new
- Jasmine.stub(:find_unused_port).and_return('1234')
- config.port.should == '1234'
- Jasmine.stub(:find_unused_port).and_return('4321')
- config.port.should == '1234'
- end
- end
describe "src_mapper" do
it "should update the src_mapper in the user_config" do
@@ -136,23 +106,25 @@
end
describe "jasmine_server_url" do
- subject { Jasmine::RunnerConfig.new.jasmine_server_url }
-
- let(:host) { "the host" }
- let(:port) { "484" }
- before do
- Jasmine::RunnerConfig.any_instance.should_receive(:jasmine_host).and_return(host)
- Jasmine::RunnerConfig.any_instance.should_receive(:port).and_return(port)
+ it "should return the correct server url" do
+ host = "the host"
+ port = "484"
+ user_config = double('config', :jasmine_host => host, :port => port)
+ Jasmine::RunnerConfig.new(user_config).jasmine_server_url.should == "#{host}:#{port}/"
end
-
- it("") { should eq("#{host}:#{port}/")}
end
+ describe "port" do
+ it "should return the port from the config" do
+ user_config = double('config', :port => 80)
+ Jasmine::RunnerConfig.new(user_config).port.should == 80
+ end
+ end
describe "result batch size" do
subject { Jasmine::RunnerConfig.new.result_batch_size }
context "when not specified" do
- it("should use default") { should eq(50) }
+ it("should use default") { should == 50 }
end
context "when overridden" do

0 comments on commit 977634f

Please sign in to comment.