Просмотр исходного кода

Fixed bug: RSpec tests are broken because of not using RSpec hooks and structures.

Thorsten Eckel 6 лет назад
Родитель
Сommit
7d9c087a84
3 измененных файлов с 27 добавлено и 18 удалено
  1. 13 0
      spec/factories/taskbar.rb
  2. 10 16
      spec/models/taskbar_spec.rb
  3. 4 2
      spec/models/translation_spec.rb

+ 13 - 0
spec/factories/taskbar.rb

@@ -0,0 +1,13 @@
+FactoryBot.define do
+  factory :taskbar do
+    client_id 123
+    key       'Ticket-1234'
+    add_attribute(:callback) { 'TicketZoom' }
+    params    do
+      {}
+    end
+    state  {}
+    prio   1
+    notify false
+  end
+end

+ 10 - 16
spec/models/taskbar_spec.rb

@@ -3,20 +3,16 @@ require 'rails_helper'
 RSpec.describe Taskbar do
 
   context 'single creation' do
-    Taskbar.destroy_all
-    UserInfo.current_user_id = 1
-
-    taskbar = Taskbar.create(
-      client_id: 123,
-      key: 'Ticket-1234',
-      callback: 'TicketZoom',
-      params: {
-        id: 1234,
-      },
-      state: {},
-      prio: 1,
-      notify: false,
-    )
+
+    let(:taskbar) do
+
+      Taskbar.destroy_all
+      UserInfo.current_user_id = 1
+
+      create(:taskbar, params: {
+               id: 1234,
+             })
+    end
 
     it 'existing key' do
       expect(taskbar.key).to eq('Ticket-1234')
@@ -79,8 +75,6 @@ RSpec.describe Taskbar do
       expect(taskbar.last_contact.to_s).not_to eq(last_contact1.to_s)
       expect(taskbar.last_contact.to_s).not_to eq(last_contact2.to_s)
     end
-
-    UserInfo.current_user_id = nil
   end
 
   context 'multible creation' do

+ 4 - 2
spec/models/translation_spec.rb

@@ -2,8 +2,10 @@ require 'rails_helper'
 
 RSpec.describe Translation do
 
-  Translation.where(locale: 'de-de').destroy_all
-  Translation.sync('de-de')
+  before(:all) do
+    Translation.where(locale: 'de-de').destroy_all
+    Translation.sync('de-de')
+  end
 
   context 'default translations' do