1
我想使用相同的rpsec測試用例來測試不同的網站,例如,我可以一次測試所有網站,也可以測試其中一個網站一次。 你介意給我一些建議嗎?我怎樣才能以簡單的方式做到這一點。如何使用相同的rpsec測試用例來測試不同的網站
我的寶石安裝rspec,而不是rspec-rails。 這是我的代碼
require 'spec_helper'
require 'net/http'
require 'json'
require 'uri'
describe 'mywebsite1' do
uri = URI.parse('http://mywebsite1/')
initheader = {'Content-Type' =>'application/json'}
req = Net::HTTP::Post.new(uri, initheader)
describe 'common_test' do
payload = JSON.parse(open("file.json").read)
req.body = payload.to_json
context 'case1' do
res = Net::HTTP.start(uri.host, uri.port) do |http|
http.request(req)
end
result = JSON.parse(res.body)
it "should response with the code 201" do
expect("#{res.code}").to eq '201'
end
specify "status is Ready" do
expect(result['item']['status']).to eq 'Ready'
end
specify "type is All" do
expect(result['item']['type']).to eq 'All'
end
end
context 'case2' do
...
end
end
end
看到進一步的細節這完全是我想要做的,謝謝vvvvvvvvvery多 –