spec/requests/monitoring_spec.rb in pulse-meter-rails-0.1.1 vs spec/requests/monitoring_spec.rb in pulse-meter-rails-0.1.2

- old
+ new

@@ -8,47 +8,61 @@ end describe "/monitoring/pages/:id/widgets" do let(:custom_tab) {1} let(:monitoring_tab) {2} - def visit_tab(tab_id) + + before(:each) do PulseToolbox::Sensor::Manager.create_sensors - custom = PulseMeter::Sensor::Timelined::Counter.new(:custom_sensor, - :ttl => 1.hour, - :interval => 1.minute, - :raw_data_ttl => 10.minutes, - :reduce_delay => 2.minutes, - :annotation => "custom_sensor" + PulseMeter::Sensor::Timelined::Counter.new(:custom_sensor, + ttl: 1.hour, + interval: 1.minute, + raw_data_ttl: 10.minutes, + reduce_delay: 2.minutes, + annotation: "custom_sensor" ) + end + + def widgets_on_tab(tab_id) visit "/monitoring/pages/#{tab_id}/widgets" - @widgets = JSON.parse(page.source) + JSON.parse(page.source) end - def all_annotations + def sensor_names_on_tab(tab_id) found_annotations = [] - @widgets.each do |w| + widgets_on_tab(tab_id).each do |w| w["series"].each do |s| found_annotations << s["name"] end end found_annotations end it "returns some groups of widgets" do - visit_tab(monitoring_tab) groups = [] PulseToolbox::Sensor::Manager.each_group {|g| groups << g} - @widgets.count.should == groups.count + widgets_on_tab(monitoring_tab).count.should == groups.count end it "contains all sensors from PulseToolbox::Sensor::Manager config" do - visit_tab(monitoring_tab) - annotations = PulseToolbox::Sensor::Manager.sensors.map(&:annotation) + PulseToolbox::Sensor::Manager.log_request(3, { + view_runtime: 2, + db_runtime: 1, + action: "foo", + controller: 'BarController', + status: 200, + }) - annotations.sort.should == all_annotations.sort + annotations = PulseToolbox::Sensor::Manager.sensors.reject{|s| + s.is_a?(PulseMeter::Sensor::Timelined::HashedCounter) + }.map(&:annotation) + + annotations << "Status: 200" + annotations << "Action: BarController#foo" + + sensor_names_on_tab(monitoring_tab).sort.should == annotations.sort end it "returns widgets of custom page created in initializer" do - visit_tab(custom_tab) - all_annotations.should == ["custom_sensor"] + sensor_names_on_tab(custom_tab).should == ["custom_sensor"] end end